import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public class A {
	static InputReader in;
	static PrintWriter out;
	public static void main(String[] args) throws Exception {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);

		int output =-1;
		int[] arr= new int[5];
		for(int input =0;input<arr.length;input++)
		{
			arr[input] = in.nextInt();
		}
		for(int m = 0 ;m<arr.length;){
			int max =arr[m];
			int min =arr[m];
			int maxIndex =0;
			int minIndex = 0;
			int value = arr[m];
			boolean isSame = true;

			for(int i =0;i<arr.length;i++){
				if(arr[i]>max){
					max =arr[i];
					maxIndex = i;
				}
				if(arr[i]<min){
					min =arr[i];
					minIndex =i;
				}
				if(value != arr[i]){
					isSame = false;
				}

			}
			if(isSame){
				output = arr[0];
			}
			if((arr[maxIndex] - arr[minIndex])> 1){
				arr[maxIndex] = arr[maxIndex] -1;
				arr[minIndex] = arr[minIndex] +1;
			}else{
				break;
			}

		}
		out.println(count);

		out.close();
	}

	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String nextToken() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return isWhitespace(c);
		}

		public static boolean isWhitespace(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}


import java.util.Scanner;
public class Answer1 {
    public static void main(String args[])
    {
        Scanner input=new Scanner(System.in);
        int ans=0;
        for(int i=0;i<5;i++)
        {
            ans+=input.nextInt();
        }
        if(ans%5==0 && ans=0)
            System.out.println((ans/5));
        else
            System.out.println("-1");
    }

}


import java.util.Scanner;

/**
 *
 * @author Simran
 */
public class Bet {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s = new Scanner(System.in);
        int a= s.nextInt();
        int b= s.nextInt();
        int c= s.nextInt();
        int d= s.nextInt();
        int e= s.nextInt();
        int sum= a+b+c+d+e;
        if(a=b=c=d=e=0){
        System.out.println("0");
        }
        if(sum%5==0){
        System.out.println(sum/5);
        }
        else{
        System.out.println("-1");
        }

    }

}


public class Main {

	public static void Main(String[] args){
		Scanner in = new Scanner(System.in);
		int c1, c2, c3, c4, c5, b, B;
		c1 = in.nextInt();
		c2 = in.nextInt();
		c3 = in.nextInt();
		c4 = in.nextInt();
		c5 = in.nextInt();
		b = (c1+c2+c3+c4+c5)/5;
		if(b%5 != 0){
			System.out.print("-1");
		}else{
			System.out.println(b);
		}

	}
}
// 1459206985986


import java.util.Scanner;

public class Test{
    public static void main(Strin []args){
        Scanner sc = new Scanner(System.in);
		String a = sc.next();
		int[] b = {-1,0};
		for(int i=0;i<a.length();i++){
		    if(a.charAt(i)=='A' || a.charAt(i)=='E' || a.charAt(i)=='I' || a.charAt(i)=='O' || a.charAt(i)=='U'){
		        if(b[0]==-1){
		            b[1]=i+1;
		        }
		        if(i-b[0]>b[1]){
		            b[1]=i-b[0];
		        }
		        b[0]=i;
		    }
		}
		System.out.println(b[1]);
    }
}


import java.lang.System.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.AbstractMap.SimpleEntry;

public class MinimumJumpA{

	public static void main(String[] agrs) {

        BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));

		Integer input = buffer.readLine();

		System.out.println(execute(input));
	}

	public static String execute(String input){
		HashMap<String, Integer> map = new HashMap<String, Integer> ();

		map.put("A", 1);
		map.put("E", 2);
		map.put("I", 3);
		map.put("O", 4);
		map.put("U", 5);
		map.put("Y", 6);

		Integer minimumJump = 1;
		Integer tmpMiniJump = 1;
		boolean isLanding = false;
		for(int i=0; i<input.length(); i++){

			String tmpC = Character.toString(input.charAt(i));
			if(map.containsKey(tmpC)){

				if(tmpMiniJump>minimumJump){
					minimumJump = tmpMiniJump;
				}

				tmpMiniJump = 1;
			}else{
				tmpMiniJump++;
			}
		}

		return Integer.toString(minimumJump);
	}

}


import java.util.*;

public class Test
{
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        String str = s.next();
        int f =0;
        int l =0;

        for(int i=0;i<str.length();i++)
        {
            if(charAt(i) == 'A' | charAt(i)== 'E' | charAt(i) == 'I' | charAt(i) == 'O' | charAt(i) == 'U' | charAt(i) =='Y')
            {
                f = i-f;
                if(f>l)
                {
                    l=f;
                }

            }
        }
        System.out.println(l);

    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Java18 {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int count=1;
		ArrayList list=new ArrayList();
		int a=0;
		int b=0;
		for(int i=0;i<s.length();i++)
		{
			if(s.charAt(i)=='A' || s.charAt(i)=='E' || s.charAt(i)=='I' || s.charAt(i)=='O' || s.charAt(i)=='U' || s.charAt(i)=='Y')
			{
			list.add(count)	;
			count=1;
			a++;
			}
			else
			{
				count++;
				b++
			}
		}
		if(a!=0)
		System.out.println(Collections.max(list));
		else
		System.out.println("0");

	}

}


import java.io.*;
import java.util.*;

public class ZeptA {

    private static Scanner in;
    private static Output out;
    static boolean isFile = false;

    static HashMap<Integer, Boolean> map = new HashMap<>();

    public static void solve() throws Exception {
        int n = in.nextInt();
        char[] c = in.nextLine().trim().toCharArray();

        ArrayList<Integer> l = new ArrayList<>();
        for (int i = 0; i < c.length; i++)
            if (c[i] == '*') l.add(i + 1);

//        out.println(Arrays.deepToString(l.toArray()));
        int index = 0;
        while (true) {
            Integer elementIndex = l.get(index);
            if (l.size() - index < 5)
                break;

            outer:
            for (int i = index + 1; i < l.size(); i++) {
                int diff = l.get(i) - elementIndex;
                if (map.get(diff) == null) map.put(diff, true);
                else continue;
                int current = elementIndex;
                int count = 1;
//                System.out.println();
//                System.out.print(current+" ");
                while (true) {
                    if (count == 4) {
                        out.println("yes");
                        return;
                    }
                    int next = current + diff;
                    int foundIndex = Collections.binarySearch(l, next);
                    if (foundIndex < 0) {
                        continue outer;
                    }
                    current = next;
//                    System.out.print(current + " ");
                    count++;
                }
            }

        }

        out.println("no");

    }

    static Exception exception;

    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new Runnable() {
            @Override
            public void run() {
                try {
                    initReaderWriter();
                    solve();
                    out.close();
                } catch (Exception ex) {
                    exception = ex;
                }
            }
        }, "", 1 << 26);
        thread.start();
        thread.join();

        if (exception != null) {
            throw exception;
        }
    }

    private static void initReaderWriter() throws Exception {
        if (isFile) {
            in = new Scanner("input.txt");
            out = new Output(new File("output.txt"));
        } else {
            in = new Scanner();
            out = new Output(System.out);
        }
    }

    private static boolean log = false;

    public static void log(String msg) {
        if (log) {
            out.println(msg);
            out.flush();
        }
    }

    private static class Scanner {

        StringTokenizer st = null;
        BufferedReader bf;

        public Scanner() {
            bf = new BufferedReader(new InputStreamReader(System.in));
        }

        public Scanner(String fileName) throws FileNotFoundException {
            bf = new BufferedReader(new FileReader(fileName));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(bf.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return bf.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    }

    private static class Output extends PrintStream {

        public Output(OutputStream out) {
            super(new BufferedOutputStream(out));
        }

        public Output(File file) throws FileNotFoundException {
            super(new BufferedOutputStream(new FileOutputStream(file)));
        }
    }
}


import java.util.Scanner;

public class Thief
{
	public boolean good(int segments, String seg, int l)
	{
		int good = 0;
		int index = -1;
		boolean isGood = false;

		if(segments < 4)
		{
			return False;
		}

		for (int i = 0; i < l; i++)
		{
			while(!isGood && index < segments)
			{
				if (index == -1)
				{
					if(seg.charAt(0) == '*')
					{
						good ++;
						if(good == 4)
							isGood = true;
							return true;

					}
					else
						good = 0;
					index = index + l;
				}
				else
				{

					if(seg.charAt(index) == '*')
					{
						good ++;
						if(good == 4)
							isGood = true;
							return true;
					}
					else
						good = 0;
					index = index + l;
				}
			}
		}
		return isGood;
	}
	public static void main(String[] args)
	{
		int segments;
		boolean good = false;
		Scanner sc = new Scanner(System.in);
		segments = sc.nextInt();
		String seg = new String();
		seg = sc.next();
		Thief game = new Thief();
		int l = segments / 4;
		for (int i = 1; i <= l; i++)
		{
			if(game.good(segments, seg, i))
			{
				good = true;
				i = l+1;
			}
			else
			{
				good = false;
			}
		}
		if(good)
			System.out.println("yes");
		else
			System.out.println("no");
	}
}


import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;

public class ZeptA {

    private static Scanner in;
    private static Output out;
    static boolean isFile = false;

    static HashMap<Integer, Boolean> map = new HashMap<>();

    public static void solve() throws Exception {
        int n = in.nextInt();
        char[] c = in.nextLine().trim().toCharArray();

        ArrayList<Integer> l = new ArrayList<>();
        for (int i = 0; i < c.length; i++)
            if (c[i] == '*') l.add(i + 1);

        int index = 0;
        if (l.isEmpty()) {
            out.print(0);
            return;
        }
        while (true) {
            Integer elementIndex = l.get(index);
            if (l.size() - index < 5)
                break;

            outer:
            for (int i = index + 1; i < l.size(); i++) {
                int diff = l.get(i) - elementIndex;
                int current = elementIndex;
                int count = 1;
                while (true) {
                    if (count == 4) {
                        out.println("yes");
                        return;
                    }
                    int next = current + diff;
                    int foundIndex = Collections.binarySearch(l, next);
                    if (foundIndex < 0) {
                        continue outer;
                    }
                    current = next;
                    count++;
                }
            }
            index++;
        }

        out.println("no");

    }

    static Exception exception;

    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new Runnable() {
            @Override
            public void run() {
                try {
                    initReaderWriter();
                    solve();
                    out.close();
                } catch (Exception ex) {
                    exception = ex;
                }
            }
        }, "", 1 << 26);
        thread.start();
        thread.join();

        if (exception != null) {
            throw exception;
        }
    }

    private static void initReaderWriter() throws Exception {
        if (isFile) {
            in = new Scanner("input.txt");
            out = new Output(new File("output.txt"));
        } else {
            in = new Scanner();
            out = new Output(System.out);
        }
    }

    private static boolean log = false;

    public static void log(String msg) {
        if (log) {
            out.println(msg);
            out.flush();
        }
    }

    private static class Scanner {

        StringTokenizer st = null;
        BufferedReader bf;

        public Scanner() {
            bf = new BufferedReader(new InputStreamReader(System.in));
        }

        public Scanner(String fileName) throws FileNotFoundException {
            bf = new BufferedReader(new FileReader(fileName));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(bf.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return bf.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    }

    private static class Output extends PrintStream {

        public Output(OutputStream out) {
            super(new BufferedOutputStream(out));
        }

        public Output(File file) throws FileNotFoundException {
            super(new BufferedOutputStream(new FileOutputStream(file)));
        }
    }
}
33333


import java.util.Scanner;

public class ZEPTO{
   public static void main(String[] args){
       Scanner scanner = new Scanner(System.in);
       int n = scanner.nextInt();
       char c[] = new char[n];
       for(int i=0;i<n;i++){
           c[i] = scanner.next();
       }
       boolean b = false;
       for(int i=1;i<n/4;i++){
            int s = 0;
            for(int j=0;j<n/i;j++){
                if(c[i*j] == '*'){
                    s ++;
                    if(s > 4){
                        b = true;
                        break;
                    }
                }else{
                   s = 0;
                }
            }
           if(b){
               break;
           }
       }
      if(b){
         System.out.println("yes");
       }
   }
}


 import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[6];
        int[] count = new int[10];
        int body = -1;
        for(int i=0;i<6;i++) {
            a[i] = sc.nextInt();
            count[a[i]]++;
            if (count[a[i]] >= 4) {
                body = a[i];
                count[a[i]]-=4;
            }
        }
        if (body == -1) {
            System.out.println("Alien");
            return;
        }
        for(int i=0;i<=9;i++) {
            if (count[i] == 2) {
                System.out.println("Elephant");
                return;
            }else if(count[i] == 1) {
                System.out.println("Bear");
                return;
            }
        }

    }


 *
 * @author Administrator
 */
import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Rd269A implements Runnable {

    public void solve() throws Exception {
        int n = 6;
        int[] ar = new int[6];
        for(int i = 0; i < n; i++)
            ar[i] = sc.nextInt();
        String res = helper(ar);
        out.println(res);
    }
    public String helper(int[] ar) {
        int len = ar.length;
        Arrays.sort(ar);
        int[] st = new int[10];
        for(int i = 0; i < len; i++)
            st[ar[i] - 1]++;
        int max = 0;
        for(int i = 0; i < 9; i++)
            max = Math.max(max, st[i]);
        if(max < 4)
            return "Alien";
        else if(max == 5)
            return "Bear";
        else if(max == 6)
            return "Elephant";
        else {
            int sec = 0;
            for(int i = 0; i < 9; i++)
                if(st[i] != 4)
                    sec = Math.max(sec, st[i]);
            if(sec == 2)
                return "Elephant";
            else
                return "Bear";
        }

    }

    static Throwable uncaught;

    BufferedReader in;
    FastScanner sc;
    PrintWriter out;

    @Override
    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            sc = new FastScanner(in);
            solve();
        } catch (Throwable uncaught) {
            Rd269A.uncaught = uncaught;
        } finally {
            out.close();
        }
    }

    public static void main(String[] args) throws Throwable {
        Thread thread = new Thread(null, new Rd269A(), "", (1 << 26));
        thread.start();
        thread.join();
        if (Rd269A.uncaught != null) {
            throw Rd269A.uncaught;
        }
    }

}

class FastScanner {

    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }

}


/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner obj=new Scanner(System.in);
        int arr[]=new int[10];

        for(int i=1;i<=6;i++)
        {
        int l=obj.nextInt();
         arr[l]++;
        }

        Arrays.sort(arr);
        if(arr[9]>=4)
        {
            if(arr[9]==4)
            {
            if(arr[8]==2){System.out.println("Elephant");break;}
            else { System.out.println("Bear");break; }
            }

            else if(arr[9]==6){System.out.println("Elephant");break;}

            else if(arr[9]==5){ System.out.println("Bear");break;}
        }
        else if(arr[9]<4)
        { System.out.println("Alien");break; }

    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int[] a = new int[6];
			for (int i = 0; i < 6; i++) {
				a[i] = in.nextInt();
			}
			Arrays.sort(a);

			if (a[0] == a[3]) {
				if (a[4] == a[5])
					System.out.println("Elephant");
				else
					System.out.println("Bear");
			} else if (a[1] == a[4])
					System.out.println("Bear");
			else if (a[2] == a[5]) {
				if (a[1] == a[0])
					System.out.println("Elephant");
				else
					System.out.println("Bear");
			} else
					System.out.println("Alien");
		}
		in.close();
	}

}


import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Solution {
	public static int minOperations(List<Integer> a, int threshold, int d) {
		int MAX = 50;
		List<Integer>[] lists = new ArrayList[MAX];
		for (int i = 0; i < lists.length; i++) {
			lists[i] = new ArrayList<Integer>();
		}
		for (int i = 0; i < a.size(); i++) {
			int n = a.get(i);
			int count = 0;
			lists[n].add(0);
			while (n > 0) {
				n /= d;
				lists[n].add(count);
			}
		}
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < lists.length; i++) {
			int m = lists[i].size();
			if (m >= threshold) {
				int moves = 0;
				Collections.sort(lists[i]);
				for (int j = 0; j < threshold; j++) {
					moves += lists[i].get(j);
				}
				ans = Math.max(ans, moves);
			}
		}
		return ans;
	}
}

	public static void main(String[] args) throws IOException {
		Scanner bufferedReader = new Scanner(System.in);
		int arrCount = bufferedReader.nextInt();
		List<Integer> arr = new ArrayList<Integer>();
		int threshold = bufferedReader.nextInt();
		for (int i = 0; i < arrCount; i++) {
			arr.add(bufferedReader.nextInt());
		}
//		int d = bufferedReader.nextInt();
		int result = minOperations(arr, threshold, 2);
		System.out.println(result);
		bufferedReader.close();

	}
}


import java.util.*;
import java.lang.*;
// StringBuilder uses java.lang

public class mainClass {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder st=new StringBuilder();
        int n = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<Integer> ok = new ArrayList<>();
        ArrayList<ArrayList<Integer>> then = new ArrayList<>();
        for (int t=0; t<=2*(10**5);t++) {
            ArrayList<Integer> ne = new ArrayList<>();
            then.add(ne);
        }
        for (int t=0; t<n; t++) {
            int r = sc.nextInt();
            ok.add(r);
        }
        Collections.sort(ok);
        for (int elt:ok) {
            int l=0;
            while (elt>0) {
                then.get(elt).add(l);
                l++;
                elt/=2;
            }
            then.get(0).add(l);
        }
        int ans=10**9;
        for (int i=0;i<=2*(10**5);i++) {
            if (then.get(i).size()>=k) {
                int okthen=0;
                for (int j=0;j<k;j++) {
                    okthen+=then.get(i).get(j);
                }
                ans=Math.min(okthen,ans);
            }
        }
        System.out.println(ans);
    }
}


        import java.util.*;
        import java.lang.*;
        // StringBuilder uses java.lang

        public class mainClass {

            public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                StringBuilder st=new StringBuilder();
                int n = sc.nextInt();
                int k = sc.nextInt();
                ArrayList<Integer> ok = new ArrayList<>();
                ArrayList<ArrayList<Integer>> then = new ArrayList<>();
                for (int t=0; t<=2*(Math.pow(10,5));t++) {
                    ArrayList<Integer> ne = new ArrayList<>();
                    then.add(ne);
                }
                for (int t=0; t<n; t++) {
                    int r = sc.nextInt();
                    ok.add(r);
                }
                Collections.sort(ok);
                for (int elt:ok) {
                    int l=0;
                    while (elt>0) {
                        then.get(elt).add(l);
                        l++;
                        elt/=2;
                    }
                    then.get(0).add(l);
                }
                int ans=Math.pow(10,9);
                for (int i=0;i<=2*(Math.pow(10,5));i++) {
                    if (then.get(i).size()>=k) {
                        int okthen=0;
                        for (int j=0;j<k;j++) {
                            okthen+=then.get(i).get(j);
                        }
                        ans=Math.min(okthen,ans);
                    }
                }
                System.out.println(ans);
            }
        }


import java.util.*;
import java.math.*;
public class Main{
        private int max=200*1000+5;
        public static void main(String args[]){
                Scanner sc=new Scanner(System.in);
                int n=sc.nextInt();
                int k=sc.nextInt();
                int a[]=new int[n];
                for(int i=0;i<n;i++){
                        a[i]=sc.nextInt();
                }
                List<Integer> [] vals=new ArrayList<Integer>[max];
                for(int i=0;i<max;i++){
                        vals[i]=new ArrayList<Integer>();
                }
                for(int i:a){
                        int y=i;
                        int cur=0;
                        while(y>0){

                                vals[y].add(cur);
                                y=y/2;
                                cur++;
                        }
                }
                int res=Integer.MAX_VALUE;
                for(List<Integer> l:vals){
                        if(l.size()>=k){
                                Collections.sort(l);
                                int t=0;
                                for(int i=0;i<k;i++){
                                        t+=l.add(i);
                                }
                                 res=Math.min(t,res);
                        }

                }
                System.out.println(res);
        }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Task {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA s = new TaskA();
		s.solve(in, out);
		out.close();
	}
}

class TaskA {
	public void solve(InputReader in, PrintWriter out) {
		int a=in.nextInt();
		int b=in.nextInt();
		int w=in.nextInt();
		int x=in.nextInt();
		int c=in.nextInt();

		if(c<=a){
			out.println(0);
			return;
		}

		int[] mod=new int[w];
		int[] d=new int[w];
		int[] loopIndex=new int[w];
		Arrays.fill(mod, -1);
//		mod[b]=0;
		int loop=0;
		int loopTotal=0;
		int index=1;
		int lastLoop=0;
		for(int i=1;;i++){
			if(b>=x){
				b-=x;
				d[b]=0;
				if(mod[b]!=-1){
					break;
				}else{
					mod[b]=i;
					lastLoop=i;
				}
			}else{
				b=w+b-x;
				d[b]=1;
				loopIndex[index++]=i;
				if(mod[b]!=-1){
					if(d[b]==0){

					}
					break;
				}else{
					mod[b]=i;
					if(d[b]==1){
						loopTotal++;
					}
				}
			}
			loop++;
		}

		int t=(c-a)/(loop-loopTotal);
		int s=(c-a)%(loop-loopTotal);

		int ss=0;
		int sss=s;
		while(sss>0){
			ss++;
			if(d[s]==1){
				continue;
			}else{
				sss--;
			}
		}

		int ans=0;
		if(s==0){
			ans=(t-1)*loop+lastLoop;
		}else{
			ans=t*loop+ss;
		}
		out.println(ans);
	}

}

class InputReader {
	private BufferedReader reader;
	private StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream));
		tokenizer = null;
	}

	public String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong(){
		return Long.parseLong(next());
	}

}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.net.ssl.SSLContext;

public class Main
{
	/********************************************** a list of common variables **********************************************/
	private MyScanner scan = new MyScanner();
	private PrintWriter out = new PrintWriter(System.out);
	private final double PI = Math.acos(-1.0);
	private final double EPS = 1e-6;
	private final int SIZEN = (int)(1e5);
	private final int MOD = (int)(1e9 + 7);
	private final long MODH = 10000000007L, BASE = 10007;
	private final int[] DX = {0, 1, 0, -1}, DY = {-1, 0, 1, 0};
	private ArrayList<Integer>[] edge;

	public void foo()
	{
		int a = scan.nextInt();
		int b = scan.nextInt();
		int w = scan.nextInt();
		int x = scan.nextInt();
		int c = scan.nextInt();
		if(b / x >= c - a)
		{
			out.println(Math.max(c - a, 0));
			return;
		}
		long ans = b / x;
		c -= b / x;
		b %= x;
		int[] index = new int[x];
		Arrays.fill(index, -1);
		index[b] = 0;
		ArrayList<Integer> arr1 = new ArrayList<Integer>();
		ArrayList<Integer> arr2 = new ArrayList<Integer>();
		int p = 1;
		while(true)
		{
			int k1 = (w - b - 1) / (w - x);
			int k2 = (b + (w - x) * k1) / x;
			b = (b + (w - x) * k1) % x;
			arr1.add(k1);
			arr2.add(k2);
			if(index[b] != -1)
			{
				p = index[b];
				break;
			}
			index[b] = p++;
		}
		long sum1 = 0, sum2 = 0;
		for(int i = b;i < arr1.size();++i)
		{
			sum1 += arr1.get(i);
			sum2 += arr2.get(i);
		}
		sum1 += sum2;
		int d = c - a;
		ans += d / sum2 * sum1;
		d %= sum2;
		if(d > 0)
		{
			for(int i = 0;i < arr1.size();++i)
			{
				if(d <= arr2.get(i))
				{
					ans += arr1.get(i) + d;
					break;
				}
				else
				{
					ans += arr1.get(i) + arr2.get(i);
					d -= arr2.get(i);
				}
			}
		}
		out.println(ans);
  	}

	public static void main(String[] args)
	{
		Main m = new Main();
		m.foo();
		m.out.close();
	}

	class Point
	{
		private int x;
		private int y;
		public Point(int aX, int aY)
		{
			x = aX;
			y = aY;
		}
	}

	/********************************************** a list of common algorithms **********************************************/
	/**
	 * 1---Get greatest common divisor
	 * @param a :	first number
	 * @param b :	second number
	 * @return		greatest common divisor
	 */
	public long gcd(long a, long b)
	{
		return 0 == b ? a : gcd(b, a % b);
	}

	/**
	 * 2---Get the distance from a point to a line
	 * @param x1	the x coordinate of one endpoint of the line
	 * @param y1	the y coordinate of one endpoint of the line
	 * @param x2	the x coordinate of the other endpoint of the line
	 * @param y2	the y coordinate of the other endpoint of the line
	 * @param x		the x coordinate of the point
	 * @param y		the x coordinate of the point
	 * @return		the distance from a point to a line
	 */
	public double getDist(long x1, long y1, long x2, long y2, long x, long y)
	{
		long a = y2 - y1;
		long b = x1 - x2;
		long c = y1 * (x2 - x1) - x1 * (y2 - y1);
		return Math.abs(a * x + b * y + c) / Math.sqrt(a * a + b * b);
	}

	/**
	 * 3---Get the distance from one point to a segment (not a line)
	 * @param x1	the x coordinate of one endpoint of the segment
	 * @param y1	the y coordinate of one endpoint of the segment
	 * @param x2	the x coordinate of the other endpoint of the segment
	 * @param y2	the y coordinate of the other endpoint of the segment
	 * @param x		the x coordinate of the point
	 * @param y		the y coordinate of the point
	 * @return		the distance from one point to a segment (not a line)
	 */
	public double ptToSeg(long x1, long y1, long x2, long y2, long x, long y)
	{
		double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);
		if(cross <= 0)
		{
			return (x - x1) * (x - x1) + (y - y1) * (y - y1);
		}
		double d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
		if(cross >= d)
		{
			return (x - x2) * (x - x2) + (y - y2) * (y - y2);
		}
		double r = cross / d;
		double px = x1 + (x2 - x1) * r;
		double py = y1 + (y2 - y1) * r;
		return (x - px) * (x - px) + (y - py) * (y - py);
	}

	/**
	 * 4---KMP match, i.e. kmpMatch("abcd", "bcd") = 1, kmpMatch("abcd", "bfcd") = -1.
	 * @param t:	String to match.
	 * @param p:	String to be matched.
	 * @return		if can match, first index; otherwise -1.
	 */
	public int kmpMatch(char[] t, char[] p)
	{
		int n = t.length;
		int m = p.length;
		int[] next = new int[m + 1];
		next[0] = -1;
		int j = -1;
		for(int i = 1;i < m;++i)
		{
			while(j >= 0 && p[i] != p[j + 1])
			{
				j = next[j];
			}
			if(p[i] == p[j + 1])
			{
				++j;
			}
			next[i] = j;
		}
		j = -1;
		for(int i = 0;i < n;++i)
		{
			while(j >= 0 && t[i] != p[j + 1])
			{
				j = next[j];
			}
			if(t[i] == p[j + 1])
			{
				++j;
			}
			if(j == m - 1)
			{
				return i - m + 1;
			}
		}
		return -1;
	}

	/**
	 * 5---Get the hash code of a String
	 * @param	s:	input string
	 * @return	hash code
	 */
	public long hash(String s)
	{
		long key = 0, t = 1;
		for(int i = 0;i < s.length();++i)
		{
			key = (key + s.charAt(i) * t) % MODH;
			t = t * BASE % MODH;
		}
		return key;
	}

	/**
	 * 6---Get x ^ n % MOD quickly.
	 * @param	x:	base
	 * @param 	n:	times
	 * @return	x ^ n % MOD
	 */
	public long quickMod(long x, long n)
	{
		long ans = 1;
		while(n > 0)
		{
			if(1 == n % 2)
			{
				ans = ans * x % MOD;
 			}
			x = x * x % MOD;
			n >>= 1;
		}
		return ans;
	}

	/**
	 * 7---judge if a point is located inside a polygon
	 * @param x0	the x coordinate of the point
	 * @param y0	the y coordinate of the point
	 * @return true if it is inside the polygon, otherwise false
	 */
	/*public boolean contains(double x0, double y0)
	{
		int cross = 0;
		for(int i = 0;i < n;++i)
		{
			double s = x[i + 1] == x[i] ? 100000000 : (double)(y[i + 1] - y[i]) / (x[i + 1] - x[i]);
			boolean b1 = x[i] <= x0 && x0 < x[i + 1];
			boolean b2 = x[i + 1] <= x0 && x0 < x[i];
			boolean b3 = y0 < s * (x0 - x[i]) + y[i];
			if((b1 || b2) && b3) ++cross;
		}
		return cross % 2 != 0;
	}*/

	/**
	 * 8---judge if a point is located on the segment
	 * @param	x1	the x coordinate of one point of the segment
	 * @param	y1	the y coordinate of one point of the segment
	 * @param 	x2	the x coordinate of another point of the segment
	 * @param 	y2	the y coordinate of another point of the segment
	 * @param	x	the x coordinate of the point
	 * @param 	y	the y coordinate of the point
	 * @return	true if it is located on the segment, otherwise false
	 */
	public boolean isOnSeg(long x1, long y1, long x2, long y2, long x, long y)
	{
		return (x - x1) * (y2 - y1) == (x2 - x1) * (y - y1) &&
				x >= Math.min(x1, x2) && x <= Math.max(x1, x2) &&
				y >= Math.min(y1, y2) && y <= Math.max(y1, y2);
	}

	/**
	 * 9---get the cross product
	 * @param 	p1	point A
	 * @param 	p2	point B
	 * @param 	p	point O
	 * @return	cross product of OA x OB
	 */
	public long cross(Point p1, Point p2, Point p)
	{
		return (long)(p1.x - p.x) * (p2.y - p.y) - (long)(p2.x - p.x) * (p1.y - p.y);
	}

	class MyScanner
	{
	    private byte[] buf = new byte[1024];
	    private int curChar;
	    private int numChars;
	    BufferedInputStream bis = new BufferedInputStream(System.in);

	    public int read()
	    {
	        if (-1 == numChars)
	        {
	        	throw new InputMismatchException();
	        }
	        if (curChar >= numChars)
	        {
	            curChar = 0;
	            try
	            {
	                numChars = bis.read(buf);
	            }
	            catch (IOException e)
	            {
	                throw new InputMismatchException();
	            }
	            if (numChars <= 0)
	            {
	            	return -1;
	            }
	        }
	        return buf[curChar++];
	    }

	    public int nextInt()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        int sgn = 1;
	        if (c == '-')
	        {
	            sgn = -1;
	            c = read();
	        }
	        int res = 0;
	        do
	        {
	            if (c < '0' || c > '9')
	            {
	            	throw new InputMismatchException();
	            }
	            res *= 10;
	            res += c - '0';
	            c = read();
	        } while (!isSpaceChar(c));
	        return res * sgn;
	    }

	    public long nextLong()
	    {
	    	int c = read();
	    	while (isSpaceChar(c))
	    	{
	    		c = read();
	    	}
	    	int sgn = 1;
	    	if (c == '-')
	    	{
	    		sgn = -1;
	    		c = read();
	    	}
	    	long res = 0;
	    	do
	    	{
	    		if (c < '0' || c > '9')
	    		{
	    			throw new InputMismatchException();
	    		}
	    		res *= 10;
	    		res += c - '0';
	    		c = read();
	    	} while (!isSpaceChar(c));
	    	return res * sgn;
	    }

	    public double nextDouble()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        int sgn = 1;
	        if (c == '-')
	        {
	            sgn = -1;
	            c = read();
	        }
	        double res = 0;
	        while (!isSpaceChar(c) && c != '.')
	        {
	            if (c == 'e' || c == 'E')
	            {
	            	return res * Math.pow(10, nextInt());
	            }
	            if (c < '0' || c > '9')
	            {
	            	throw new InputMismatchException();
	            }
	            res *= 10;
	            res += c & 15;
	            c = read();
	        }
	        if (c == '.')
	        {
	            c = read();
	            double m = 1;
	            while (!isSpaceChar(c))
	            {
	                if (c == 'e' || c == 'E')
	                {
	                	return res * Math.pow(10, nextInt());
	                }
	                if (c < '0' || c > '9')
	                {
	                	throw new InputMismatchException();
	                }
	                m /= 10;
	                res += (c & 15) * m;
	                c = read();
	            }
	        }
	        return res * sgn;
	    }

	    public String next()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        StringBuilder res = new StringBuilder();
	        do
	        {
	            res.appendCodePoint(c);
	            c = read();
	        } while (!isSpaceChar(c));
	        return res.toString();
	    }

	    private boolean isSpaceChar(int c)
	    {
	        return ' ' == c || '\n' == c || '\r' == c || '\t' == c || -1 == c;
	    }
	}
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {

    public static Scanner cin = new Scanner(System.in);

    public static final int N = 150000;

    public static void main(String[] args) throws IOException  {
        //BufferedReader in = new BufferedReader(new FileReader(new File("D:/java.inp")));
        BufferedReader in = new BufferReader(new InputStreamReader(System.in));

        String s = in.readLine();
        String[] st = s.split(" ");
        int a = Integer.parseInt(st[0]);
        int b = Integer.parseInt(st[1]);
        int w = Integer.parseInt(st[2]);
        int x = Integer.parseInt(st[3]);
        int c = Integer.parseInt(st[4]);

        b = w-b-1;
        int l = 1, r = 2000000000, res = 0;
        while (l <= r) {
            int mid = (l+r)/2;
            int aa = a-(b+mid*x)/w;
            int cc = c-mid;
            if (cc <= aa) {
                res = mid;
                r = mid-1;
            }
            else
                l = mid+1;
        }

        System.out.print(res);
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Locale;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					long prevTime = System.currentTimeMillis();
					new Main().run();
					System.err.println("Total time: "
							+ (System.currentTimeMillis() - prevTime) + " ms");
					System.err.println("Memory status: " + memoryStatus());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start();
	}

	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		Object o = solve();
		if (o != null)
			out.println(o);
		out.close();
		in.close();
	}

	private Object solve() throws IOException {
		long a = nl();
		int b = ni();
		int w = ni();
		int x = ni();
		long c = nl();

		int step = 100000;

		int[][] move_b = new int[w][step + 1];
		for (int i = 0; i < w; i++)
			move_b[i][0] = i;
		long[][] dif_b = new long[w][step + 1];
		for (int i = 0; i < w; i++)
			dif_b[i][0] = 0;

		for (int move = 1; move <= step; move++)
			for (int bb = 0; bb < w; bb++) {
				int prev_b = move_b[bb][move - 1];
				long prev_dif = dif_b[bb][move- 1];

				if (prev_b >= x) {
					move_b[bb][move] = prev_b - x;
					dif_b[bb][move] = prev_dif;
				} else {
					move_b[bb][move] = w - (x - prev_b);
					dif_b[bb][move] = prev_dif + 1L;
				}

			}
		long t = 0;
		while (has_next(a, b, c, dif_b, step)) {
			a -= dif_b[b][step];
			b = move_b[b][step];
			t += (long) (step);
			c -= (long) (step);

		}
		while (c > a) {
			c--;
			a-= (long) (dif_b[b][1]);
			b = move_b[b][1];
			t++;
		}

		return t;
	}

	private boolean has_next(long a, int b, long c, long[][] dif_b, int step) {
		long next_c = c - (long) (step);
		long next_a = a - dif_b[b][step];
		return next_c > next_a;
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int ni() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nl() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nd() throws IOException {
		return Double.parseDouble(nextToken());
	}

	int[] nia(int size) throws IOException {
		int[] ret = new int[size];
		for (int i = 0; i < size; i++)
			ret[i] = ni();
		return ret;
	}

	long[] nla(int size) throws IOException {
		long[] ret = new long[size];
		for (int i = 0; i < size; i++)
			ret[i] = nl();
		return ret;
	}

	double[] nda(int size) throws IOException {
		double[] ret = new double[size];
		for (int i = 0; i < size; i++)
			ret[i] = nd();
		return ret;
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}

	void printRepeat(String s, int count) {
		for (int i = 0; i < count; i++)
			out.print(s);
	}

	void printArray(int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0)
				out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}

	void printArray(long[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0)
				out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}

	void printArray(double[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0)
				out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}

	void printArray(double[] array, String spec) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0)
				out.print(' ');
			out.printf(Locale.US, spec, array[i]);
		}
		out.println();
	}

	void printArray(Object[] array) {
		boolean blank = false;
		for (Object x : array) {
			if (blank)
				out.print(' ');
			else
				blank = true;
			out.print(x);
		}
		out.println();
	}

	@SuppressWarnings("rawtypes")
	void printCollection(Collection collection) {
		boolean blank = false;
		for (Object x : collection) {
			if (blank)
				out.print(' ');
			else
				blank = true;
			out.print(x);
		}
		out.println();
	}

	static String memoryStatus() {
		return (Runtime.getRuntime().totalMemory()
				- Runtime.getRuntime().freeMemory() >> 20)
				+ "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB";
	}
}


import java.io.*;

public class A {
    public static void main(String[] args) {
        BufferedReader r;
         r = new BufferedReader(new InputStreamReader(System.in));
        String[] arg = r.readLine().split(" ");
        int n = Integer.parseInt(arg[0]);
        int m = Integer.parseInt(arg[1]);
        if (n == 0 && m != 0) {
            System.out.print("Impossible");
        } else {
            int max = n + ((m == 0) ? 1 : m) - 1;
            int min = (m >= n) ? m : n;
            System.out.print(min + " " + max);
        }
    }
}


public class Main {
    /**
     * @param args
     */
    public static void main(String[] args) {
        Main task = new Main();
        task.read();
        task.write();
    }

    int n,m;

    public void read() {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        in.close();
    }

    public void write() {
        PrintWriter out = new PrintWriter(System.out);
        if (n == 0 && m > 0){
            out.println("Impossible");
        }else{
            out.println((n + m - Math.min(n, m)) + " " + (n + m - (m > 0 ? 1 : 0)));
        }
        out.flush();
        out.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class AVasyaAndTheBus {

    public static void main(String[] args) throws IOException {

        BufferedReader reader= new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st=new StringTokenizer(reader.readLine());

        long n=Long.parseLong(st.nextToken());
        long m=Long.parseLong(st.nextToken());
        if(n==0&&m==0)
            System.out.println("0 0");
        else
        if(n==0)
            System.out.println("Impossible");
        else
            if(m==0)
                System.out.println(n+" "+n);
        else
                if(n==m)
                        System.out.println(n+" "+(n+(m-1)));
        else
                if(n>m)
                    System.out.println(n+" "+(n+(m-1)));
        else
                System.out.println(m+" "+(n+(m-1)));


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int min=0;
        int max=0;
        int n=sc.nextInt();
        int m=sc.nextInt();

        if(n==0)
            System.out.println("Impossible");
        else{
        if(m==0){
            max=n;
            min=n;

            }
        if(m>=n){

            min=m;
            max=m+n-1;
            }
            else
            if(m!=0)
            {
            min=n;
            max=m+n-1;
            }
         System.out.println(min+" "+max);
        }

        }
    }


import java.io.*;
import java.util.*;
public class edu121
{
   public static void main(String args[])throws IOException
   {
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	   Scanner sc = new Scanner(System.in);
	   int a = sc.nextInt();
	   int ta = sc.nextInt();

	   int b = sc.nextInt();
	   int tb = sc.nextInt();

	   String s  =  br.readLine();

	   int hr = Integer.parseInt(s.substring(0,2));
	   int mins = Integer.parseInt(s.substring(3));

	   //System.out.println(mins);
	   int min_calcu  = hr*60 + mins;
	   //int time  = min_calcu;
	   int count = 0;

		int elapse_time = min_calcu + ta;
	   for(int i = 5*60 ; i < (23*60 + 59 ); i=i+b)
	   {
		  //int time = i + tb;

            if (i +tb > min_calcu && elapse_time > i)
				count++;
	   }
	   System.out.println(count);

   }

}


import java.util.Scanner;

public class Simion {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.nextLine();
		String b = in.nextLine();
		String hora = in.nextLine();
		String [] A = a.split(" ");
		String [] B = b.split(" ");
		String [] C = c.split(":");
		int hora = (Integer.valueOf(C[0])*60) + Integer.valueOf(C[1]);
		int tiempollegada = hora + Integer.valueOf(A[1]);
		int cont=0;
		for(int i=300;i<tiempollegada;i+=Integer.valueOf(B[0])){
			if((i+Integer.valueOf(B[1]))<tiempollegada && (i+Integer.valueOf(B[1]))>hora)
				cont++;
		}
		System.out.println(cont);
    }
}


public class code {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		a = sc.nextInt();
		double b = sc.nextDouble();
		int c = sc.nextInt();
		String t = sc.next();
		int time = Integer.parseInt(String.valueOf(t.charAt(0)))*600+Integer.parseInt(String.valueOf(t.charAt(1)))*60+Integer.parseInt(String.valueOf(t.charAt(3)))*10+Integer.parseInt(String.valueOf(t.charAt(4)))-300;
		int max= time+a;
		if(max>23*60+59-300) {
			max=23*60+59-300;
		}
		int depart=(int)(Math.ceil((max)/b));
		if(max%b==0) {
			depart++;
		}
		int arrive = 0;
		if(time>=c) {
			arrive=(int)((time-c)/b)+1;
		}
		System.out.println(depart-arrive);
	}
}


import java.util.Scanner;

public class Simion {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.nextLine();
		String b = in.nextLine();
		String c = in.nextLine();
		String [] A = a.split(" ");
		String [] B = b.split(" ");
		String [] C = c.split(":");
		int hora = (Integer.parseInt(C[0])*60) + Integer.parseInt(C[1]);
		int tiempollegada = hora + Integer.parseInt(A[1]);
		int cont=0;
		for(int i=300;i<tiempollegada;i+=Integer.parseInt(B[0])){
			if((i+Integer.parseInt(B[1]))<tiempollegada || (tiempollegada>i>=hora))
				cont++;
		}
		System.out.println(cont);
    }
}


iimport java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		int n=input.nextInt();
		String arr=input.next();
		int count=0;
		int count1=0;

		int m=n/11;
		for(int i=0;i<n;i++) {
			if(arr.charAt(i)=='8') {
				count++;
			}
		}

		if(count>m) {
			count1=m;
		}
		else {
			count1=count;
		}

		System.out.print(count1);
}
}


import java.utils.*;

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String digitStr = sc.nextLine();
        int count = 0, size = digitStr.length();

        for(int i = 0; i < size; i++) {
            if(digitStr.charAt(i) == '8') {
                count++;
            }
        }

        int div = size / 11;
        int mod = size % 11;

        if(mod != 0) return 0;

        if(count < div) return 0;

        return div;
    }
}


import java.util.*;
public class phonenumber
{
  public static void main(String args[])
  {
     Scanner as=new Scanner(System.in);
	 int n=as.nextInt();
	 String s=as.next();
	 if(n<11)
		 System.out.println(0);
	 else
	 {
		 int flag=0;int c=0;
		 for(int i=0;i<n;i++){
			 if(s.charAt(i)=='8'){
				 c++;
			 }
		 }
		 if(c==0)
			 System.out.println(0);
		 else{
			    min(n/11,c);

		 }
	 }
  }
  static int min(int a,int b)
  {
	  if(a<b)
		  return a;
	  else
		  return b;
  }


import java.util.*;

public class 1060A {
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  String s = sc.next();

  int count=0;
  for (int i=0;i<n;i++){
   if (n.charAt(i) == '8'){
    count++;
   }
  }
  int floor = (int) Math.floor(n/11);
  int asdf = Math.min(count,floor);
  System.out.println(asdf);
 }
}


import java.util.Scanner;

public class B_CodeforcesWorldFinals {

    /**
     * 0:14
     */
    public static void main(String[] args) {

//      System.out.println(days(new int[]{1, 12,31}));
//      if(true) return;
        Scanner sc = new Scanner(System.in);

        String[] p1;
        p1 = sc.nextLine().split("\\.");
        int DD = Integer.parseInt(p1[0]);
        int MM = Integer.parseInt(p1[1]);
        int YY = Integer.parseInt(p1[2]);

        p1 = sc.nextLine().split("\\.");
        int BD = Integer.parseInt(p1[0]);
        int BM = Integer.parseInt(p1[1]);
        int BY = Integer.parseInt(p1[2]);

        int[][] perm = new int[][]{{BY, BM, BD}, {BY, BD, BM}, {BM, BD, BY}, {BM, BY, BD}, {BD, BY, BM}, {BD, BM, BY}};

        int hd = days(new int[]{YY, MM, DD});
        for (int i = 0; i < 6; i++) {
            int[] p = perm[i];
            if(p[1] == 2 && p[2] == 29){
                p[1] = 3;
                p[2] = 1;
            }
            p[0] += 18;

            int bd = days(p);

            if(bd <= hd){
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }

    static final int[] mds = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
    private static int days(int[] p){
        if(! isValid(p)) return Integer.MAX_VALUE;

        int ret = 0;

        for (int y = 0; y <= p[0]; y++) {
            for (int m = 1; m <= (y == p[0] ? p[1] : 12); m++) {
                ret += mds[m-1];
                if(y%4 == 0 && m == 2) ret++;
            }
            if(y == p[0]){
                ret += p[2];
            }
        }
        return ret;
    }

    private static boolean isValid(int[] p){
        if(p[0] < 1 || p[0] > 99) return false;
        if(p[1] < 1 || p[1] > 12) return false;
        if(p[2] < 1 || p[2] > mds[p[1]]) return false;
        if(p[0]%4!=0 && p[1]==2 && p[2] == 29) return false;
        return true;
    }

}


import java.util.Calendar;
import java.util.Scanner;
import java.util.TimeZone;

public class B_CodeforcesWorldFinals {

    /**
     * 0:14
     */

    static final int INF = 100000000;
    public static void main(String[] args) {

//      System.out.println(days2(new int[]{1, 12, 31}));
//      if(true) return;
        Scanner sc = new Scanner(System.in);

        String[] p1;
        p1 = sc.nextLine().split("\\.");
        int DD = Integer.parseInt(p1[0]);
        int MM = Integer.parseInt(p1[1]);
        int YY = Integer.parseInt(p1[2]);

        p1 = sc.nextLine().split("\\.");
        int BD = Integer.parseInt(p1[0]);
        int BM = Integer.parseInt(p1[1]);
        int BY = Integer.parseInt(p1[2]);

        int[][] perm = new int[][]{{BY, BM, BD}, {BY, BD, BM}, {BM, BD, BY}, {BM, BY, BD}, {BD, BY, BM}, {BD, BM, BY}};

        int hd = days2(new int[]{YY, MM, DD});
        if(hd == INF) throw new RuntimeException();
        System.out.println(hd);
        for (int i = 0; i < 6; i++) {
            int[] p = perm[i];
            if(p[1] == 2 && p[2] == 29){
                p[1] = 3;
                p[2] = 1;
            }
            p[0] += 18;

            int bd = days2(p);
            System.out.println(bd);

            if(bd <= hd){
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }

    static final int[] mds = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
    private static int days(int[] p){
        if(! isValid(p)) return INF;

        int ret = 0;

        for (int y = 0; y <= p[0]; y++) {
            for (int m = 1; m <= (y == p[0] ? p[1] : 12); m++) {
                ret += mds[m-1];
                if(y%4 == 0 && m == 2) ret++;
            }
            if(y == p[0]){
                ret += p[2];
            }
        }
        return ret;
    }
    private static int days2(int[] p){

        if(! isValid(p)) return INF;
        int day = calcDay(2000+p[0], p[1], p[2]);

        return day;

    }

    private static int calcDay(int y, int m, int d){
        Calendar cl = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cl.set(y, m-1, d, 0, 0, 0);
        cl.set(Calendar.MILLISECOND, 0);
        return (int)(cl.getTimeInMillis() / 1000 / 60 / 60 / 24);
    }

    private static boolean isValid(int[] p){
        if(p[0] > 99) return false;
        if(p[1] < 1 || p[1] > 12) return false;
        if(p[2] < 1 || p[2] > mds[p[1]-1]) return false;
        if(p[0]%4!=0 && p[1]==2 && p[2] == 29) return false;
        return true;
    }

}


import java.util.Calendar;
import java.util.Scanner;
import java.util.TimeZone;

public class B_CodeforcesWorldFinals {

    /**
     * 0:14
     */

    static final int INF = 100000000;
    public static void main(String[] args) {

//      System.out.println(days2(new int[]{1, 12, 31}));
//      if(true) return;
        Scanner sc = new Scanner(System.in);

        String[] p1;
        p1 = sc.nextLine().split("\\.");
        int DD = Integer.parseInt(p1[0]);
        int MM = Integer.parseInt(p1[1]);
        int YY = Integer.parseInt(p1[2]);

        p1 = sc.nextLine().split("\\.");
        int BD = Integer.parseInt(p1[0]);
        int BM = Integer.parseInt(p1[1]);
        int BY = Integer.parseInt(p1[2]);

        int[][] perm = new int[][]{{BY, BM, BD}, {BY, BD, BM}, {BM, BD, BY}, {BM, BY, BD}, {BD, BY, BM}, {BD, BM, BY}};

        int hd = days2(new int[]{YY, MM, DD});
        if(hd == INF) throw new RuntimeException();
//      System.out.println(hd);
        for (int i = 0; i < 6; i++) {
            int[] p = perm[i];
            if(p[1] == 2 && p[2] == 29){
                p[1] = 3;
                p[2] = 1;
            }
            p[0] += 18;

            int bd = days2(p);
//          System.out.println(bd);

            if(bd <= hd){
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }

    static final int[] mds = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
    private static int days(int[] p){
        if(! isValid(p)) return INF;

        int ret = 0;

        for (int y = 0; y <= p[0]; y++) {
            for (int m = 1; m <= (y == p[0] ? p[1] : 12); m++) {
                ret += mds[m-1];
                if(y%4 == 0 && m == 2) ret++;
            }
            if(y == p[0]){
                ret += p[2];
            }
        }
        return ret;
    }
    private static int days2(int[] p){

        if(! isValid(p)) return INF;
        int day = calcDay(2000+p[0], p[1], p[2]);

        return day;

    }

    private static int calcDay(int y, int m, int d){
        Calendar cl = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cl.set(y, m-1, d, 0, 0, 0);
        cl.set(Calendar.MILLISECOND, 0);
        return (int)(cl.getTimeInMillis() / 1000 / 60 / 60 / 24);
    }

    private static boolean isValid(int[] p){
        if(p[0] > 99) return false;
        if(p[1] < 1 || p[1] > 12) return false;
        if(p[2] < 1 || p[2] > mds[p[1]-1]) return false;
        if(p[0]%4!=0 && p[1]==2 && p[2] == 29) return false;
        return true;
    }

}


//package round30;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class B {
	private Scanner in;
	private PrintWriter out;
//	private String INPUT = "01.01.98\n01.01.80";
//	private String INPUT = "20.10.20\n10.02.30";
//	private String INPUT = "01.03.74\n29.02.56";
	private String INPUT = "";

	public void solve()
	{
		in.useDelimiter("[\\.\n\r]");
		int dd = ni();
		int mm = ni();
		int yy = ni();
		int[] t = new int[3];
		for(int i = 0;i < 3;i++)t[i] = ni();

		if(	test(dd, mm, yy, t[0], t[1], t[2]) ||
				test(dd, mm, yy, t[0], t[2], t[1]) ||
				test(dd, mm, yy, t[1], t[0], t[2]) ||
		test(dd, mm, yy, t[1], t[2], t[0]) ||
		test(dd, mm, yy, t[2], t[1], t[0]) ||
		test(dd, mm, yy, t[2], t[0], t[1])){
			out.println("YES");
		}else{
			out.println("NO");
		}
	}

	public boolean test(int dd, int mm, int yy, int bd, int bm, int by)
	{
		if(yy < by + 18)return false;
		if(bm > 12)return false;
		if(bd > 31)return false;

		int[] md = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
		if(by % 4 == 0)md[2]++;
		if(by % 4 != 0 && bm == 2 && bd == 29){
			bm = 3; bd = 1;
		}
		if(bd > md[bm])return false;

		if(yy > by + 18)return true;
		if(bm != mm)return mm > bm;
		return dd >= bd;
	}

	public void run() throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		solve();
		out.flush();
	}

	public static void main(String[] args) throws Exception
	{
		new B().run();
	}

	private int ni() { return Integer.parseInt(in.next()); }
	private void tr(Object... o) { if(INPUT.length() != 0)System.out.println(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }
}


import java.util.*;

public class scc
{
   public static void main(String[] args)
   {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int sum = 0;
      int x = 1;
      while(sum < n)
      {
         sum += x;
         x++;
      }
      x--;
      System.out.println(x);
      while(n-x > 0)
      {
         System.out.print(x + " ");
      }
      else
         System.out.println(n);
   }
}


import java.io.*;

public class SantaClausaAndCandies {
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int val = (int) Math.sqrt(n*2);
		if((int)Math.pow(val, 2) + val > n * 2){
			val -= 1;
		}
		System.out.println(val);
		//int count = val;
		while(true){
			boolean flag = false;
			if(val == 1){
				System.out.print(n);
				break;
			}
			else{
				for(int i = 1; i <= val; i++){

					if(i == val){
						System.out.print(n - ((i)*(i-1))/2);
						flag = true;
						break;
					}
					System.out.print(i + " ");
				}
			}
			if(flag){
				return;
			}
		}
	}


import java.math.*;
import java.io.*;

public class problem2 {
	public static int isSubstring(String s1, String s2) {
		int M = s1.length();
		int N = s2.length();

		/* A loop to slide pat[] one by one */
		for (int i = 0; i <= N - M; i++) {
			int j;

			/*
			 * For current index i, check for pattern match
			 */
			for (j = 0; j < M; j++)
				if (s2.charAt(i + j) != s1.charAt(j))
					break;

			if (j == M)
				return i;
		}

		return -1;
	}

	public static void merge(int arr[], int l, int m, int r) {
		// Find sizes of two subarrays to be merged
		int n1 = m - l + 1;
		int n2 = r - m;

		/* Create temp arrays */
		int L[] = new int[n1];
		int R[] = new int[n2];

		/* Copy data to temp arrays */
		for (int i = 0; i < n1; ++i)
			L[i] = arr[l + i];
		for (int j = 0; j < n2; ++j)
			R[j] = arr[m + 1 + j];

		/* Merge the temp arrays */

		// Initial indexes of first and second subarrays
		int i = 0, j = 0;

		// Initial index of merged subarry array
		int k = l;
		while (i < n1 && j < n2) {
			if (L[i] <= R[j]) {
				arr[k] = L[i];
				i++;
			} else {
				arr[k] = R[j];
				j++;
			}
			k++;
		}

		/* Copy remaining elements of L[] if any */
		while (i < n1) {
			arr[k] = L[i];
			i++;
			k++;
		}

		/* Copy remaining elements of R[] if any */
		while (j < n2) {
			arr[k] = R[j];
			j++;
			k++;
		}
	}

	// Main function that sorts arr[l..r] using
	// merge()
	public static void sort(int arr[], int l, int r) {
		if (l < r) {
			// Find the middle point
			int m = (l + r) / 2;

			// Sort first and second halves
			sort(arr, l, m);
			sort(arr, m + 1, r);

			// Merge the sorted halves
			merge(arr, l, m, r);
		}
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int temp = 0;
		int k = 1;
		while(temp<=n) {
			temp = (k*(k+1))/2;
			k++;
		}
		k-=2;
		int sum = 0;
		System.out.println(k);
		for(int i=1;i<=k-1;i++) {
			System.out.print(i + " ");
			sum+=i;
		}
		System.out.println(n-sum);
	}
}


import java.util.Scanner;

public class CF753A {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int sum = 0;
		for (int i = 0; i <= n; i++) {
			sum += i;
			if (sum == n) {
				System.out.println(i);
				System.out.println();
				for (int i = 0; i < n; i++)
					System.out.print(i + " ");
				break;
			} else if (sum > 0) {
				System.out.println(i - 1);
				for (int i = 0; i < n - 2; i++)
					System.out.print(i + " ");
				System.out.print(n - sum + n - 1 + n);
				break;
			}
		}
	}
}


import java.lang.*;
import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		Long n = in.nextLong();
		Long k = in.nextLong();
		Long ans = 0L;
		if(k == 1)
		{
			ans = n;
		}else{
			ans = 0;
			int i;
			for(i = 63; i >= 0; i--)
			{
				if((n&1<<i) == 1)
				{
					break;
				}
			}
			for(int j = 0; j <= i; j++)
			{
				ans |= 1<<j;
			}
		}
		System.out.println(ans);
	}
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        long N = in.nextLong(), K = in.nextLong();

        if(K == 1L) {
            System.out.println(N);
            return;
        }

        int tim = -1;
        while (N > 0) {
            N /= 2;
            tim++;
        }

        long ans = 0;

        for (int i = 0; i < K && tim >= 0; i++, tim--) {
            ans += pow(tim);
        }

        System.out.println(ans);
    }

    private static long pow(int tim) {
        long ans = 1;
        for (int i = 1; i <= tim; i++) {
            ans *= 2;
        }
        return ans;
    }
}
close


public class New_Years_Eve
{
	public static void main(String[] args)
	{
		Scanner sc= new Scanner(System.in);
		long n=sc.nextLong();
		long k=sc.nextLong();
		if(k==1)
			System.out.println(n);
		else
		{
		double log2=Math.ceil(Math.log(n)/Math.log(2));
		double z=Math.pow(2, log2);
		if(z==n)
			System.out.println((long)(Math.pow(2, log2+1)-1));
		else
			System.out.println((long)(z-1));

		}
	}
}


import java.lang.*;
import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		Long n = in.nextLong();
		Long k = in.nextLong();
		Long ans = 0L;
		if(k == 1)
		{
			ans = n;
		}else{
			for(Long i = 63; i >= 0; i--)
			{
				if((n&1<<i) != 0L)
				{
					for(Long j = 0; j <= i; j++)
					{
						ans |= 1<<j;
					}
					break;
				}
			}
		}
		System.out.println(ans);
	}
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.*;
/**
 *
 * @author adib
 */
public class Main {
    public static long sumOfDigits(long x){
        long left = 0, sum = 0;
        while(x > 0){
            left = x%10;
            sum += left;
            x -= left;
            x /= 10;
        }
        return sum;
    }
    public static long Converter(long x){
            Stack st = new Stack();
            long left = 0, wanted = 0;
            boolean done = false;
            while(x > 0){
                left = x%10;
                x -= left;
                x /= 10;
                st.push(left);
            }
            while(!st.empty()){
                left = (long)st.pop();
                if(!done){
                    wanted += (left - 1);
                    done = true;
                }else{
                    wanted += 9;
                }
                wanted *= 10;
            }
            return wanted/10;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
            long x = 0;
            Scanner sc = new Scanner(System.in);
            x = sc.nextLong();
            long largestSum = 0, wantedNumber = 0;
            for(long i = Converter(x); i <= x; ++i){
                if(i >= 0){
                    long sumOfDigs = sumOfDigits(i);
                    if(sumOfDigs >= largestSum){
                        largestSum = sumOfDigs;
                        wantedNumber = i;
                    }
                }
            }
            System.out.println(wantedNumber);
    }
}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class SecondD {

    public static void main(String[] args) {
        for (int i = 0; i < 10000; i++) {
            int sumTWO = 0;
            int myRes = ree(i);
            int sumRes = getInts(myRes).stream().mapToInt(Integer::intValue).sum();

            List<Integer> qwe = new ArrayList<>();
            for (int j = 0; j <= i ; j++) {
                sumTWO = getInts(j).stream().mapToInt(Integer::intValue).sum();
                if (sumRes <= sumTWO) {
                    qwe.add(j);
                }
            }
            int max = qwe.stream().mapToInt(Integer::intValue).max().getAsInt();
            if (max != myRes) {
                System.out.println(i);
                System.out.println(max + " надо");
                System.out.println(myRes + " есть");
            }

        }

    }
    private static int ree(int x) {

        List<Integer> numbers = getInts(x);
        boolean ninesTemplate = nines(numbers);

        int[] ints = numbers.stream().mapToInt(i->i).toArray();

        int firstSum = IntStream.of(ints).sum();

        for (int i = 0; i < ints.length; i++) {
            if (ints[i] < 9) {
                if (i + 1 < ints.length) {
                    if (ints[ints.length - 2] != 8 ) {
                        ints[i] = 9;
                        ints[i + 1] = ints[i + 1] - 1;
                    }
                }
            }
        }

        int lastSum = IntStream.of(ints).sum();

        if (firstSum >= lastSum) {
            return x;
        } else if (ninesTemplate) {
            return (((int) (x / 10) * 10) - 1);
        } else {
            StringBuilder result = new StringBuilder();
            boolean flag = true;
            for (int i = ints.length - 1; i >= 0; i--) {
                if (ints[i] == 0 && flag) {
                    continue;
                }
                result.append(ints[i]);
                flag = false;
            }

            return Integer.parseInt(result.toString());
        }
    }

    private static List<Integer> getInts(int x){
        List<Integer> numbers = new ArrayList<>(15);
        while(x > 0) {
            numbers.add(x % 10);
            x = x / 10;
        }
        return numbers;
    }

    private static boolean nines(List<Integer> x) {

        for (int i = 1; i < x.size() - 1; i++) {
            if (x.get(i) != 9) {
                return false;
            }
        }
        return true;
    }
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.*;
/**
 *
 * @author adib
 */
public class Main {
    public static long sumOfDigits(long x){
        long left = 0, sum = 0;
        while(x > 0){
            left = x%10;
            sum += left;
            x -= left;
            x /= 10;
        }
        return sum;
    }
    public static long Converter(long x){
            Stack st = new Stack();
            long left = 0, wanted = 0;
            boolean done = false;
            while(x > 0){
                left = x%10;
                x -= left;
                x /= 10;
                st.push(left);
            }
            while(!st.empty()){
                left = (long)st.pop();
                if(!done){
                    wanted += (left - 1);
                    done = true;
                }else{
                    wanted += 9;
                }
                wanted *= 10;
            }
            return wanted/10;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
            long x = 0;
            Scanner sc = new Scanner(System.in);
            x = sc.nextLong();
            long largestSum = 0,wantedNumber = Converter(x);
            for(long i = Converter(x); i <= x; i*=10){
                if(i >= 0){
                    long sumOfDigs = sumOfDigits(i);
                    if(sumOfDigs >= largestSum){
                        largestSum = sumOfDigs;
                        wantedNumber = i;
                    }
                }
            }
            wantedNumber = Converter(x);
            System.out.println(sumOfDigits(x)==sumOfDigits(wantedNumber)?x:wantedNumber);
    }
}


import java.util.Scanner;

public class A {
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		long n= sc.nextLong();
		long smax=0;
		long result=0;
		for (long i= n- n+"".length(); i<=n;i++){
			long a=i;
			long l=0;
			long s=0;
			/*while(a>0){
				a=a/10;
				l=l+1;
			}*/
			l=1;
			for (long k=1; k<=l;k++){
				s=s+((i/l)%10);
				l=l*10;
			}
			if (s>=smax){
				smax=s;
				result=i;
			}

		}
		System.out.print(result);

	}

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.HashMap;
import java.util.InputMismatchException;

public class Main
{
    static class Pair implements Comparable<Pair>{
        int pro, cus,diff;
        public Pair(int pro,int cus,int diff)
        {
            this.pro =  pro;
            this.cus = cus;
            this.diff = diff;
        }
        public int compareTo(Pair p1)
        {
            if(Integer.compare(this.diff,p1.diff)==0)
                return p1.cus-this.cus;
            else
                return p1.diff-this.diff;
        }

    }
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	static class Solution
	{
		static final long mod = 1000000007;
		static final int  max = 1000003;
		static final boolean SIEVE = false;
		boolean[] prime;
		ArrayList<Integer> al;
	    public void solve(InputReader sc,PrintWriter out)
	    {
	       int n = sc.nextInt();
	       int k = sc.nextInt();
	       int sum=0;
	       for(int i=0;i<n;i++)
	       {
	           sum+=sc.nextInt();
	       }
	       out.println(((2*k-1)*n-sum*2)<0?0:(2*k-1)*n-sum*2));

    	}

    	///////////////////////////////Methods///////////////////////////////////////////////////////
       int lower_bound(int n, int x) {
    		int l = 0;
    		int h = n; // Not n - 1
    		while (l < h) {
        		int mid = (l + h) / 2;
        		if (x <= al.get(mid)) {
            		h = mid;
        		} else {
            		l = mid + 1;
        		}
    		}
    		return l;
		}
    	long fib(long n)
        {
			if(n==0) return 0;
			long a=0, b=1, c=1, d=1, e=n-2;
			long a1, b1, c1, d1, a2=0, b2=1, c2=1, d2=1;

			while(e>0){
				if(e%2==1){
					a1 = (a*a2+b*c2)%mod;
					c1 = (c*a2+d*c2)%mod;
					b1 = (a*b2+ b*d2)%mod;
					d1 = (b2*c+ d*d2)%mod;
					a=a1; b=b1; c=c1; d= d1;
				}
				a1 = (a2*a2+b2*c2)%mod;
				c1 = (c2*a2+d2*c2)%mod;
				b1 = (a2*b2+ b2*d2)%mod;
				d1 = (b2*c2+ d2*d2)%mod;
				a2=a1; b2=b1; c2=c1; d2= d1;
				e /= 2;
			}
			return d;
        }
        ///////////////////////////////////////Methods/////////////////////////////////////////////////////
 	}

 	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	Main() throws IOException {
	   	InputReader sc = new InputReader();
	    PrintWriter out= new PrintWriter(System.out);
	    final long start = System.currentTimeMillis();
		new Solution().solve(sc,out);
		@SuppressWarnings("unused")
		final long duration = System.currentTimeMillis()-start;
		out.close();
	}

	public static void main(String args[]) {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new Main();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}, "1", 1 << 26).start();
	}
	static class InputReader{
		final InputStream stream;
		final byte[] buf = new byte[8192];
		int curChar, numChars;
		SpaceCharFilter filter;

		public InputReader(){
			this.stream = System.in;
		}

		public int read(){
			if(numChars == -1){
				throw new InputMismatchException();
			}
			if(curChar >= numChars){
				curChar = 0;
				try{
					numChars = stream.read(buf);
				} catch(IOException e){
					throw new InputMismatchException();
				}
				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt(){
			int c = read();
			while(isSpaceChar(c))
				c = read();
			int sgn = 1;
			if(c == '-'){
				sgn = -1;
				c = read();
			}
			int res = 0;
			do{
				if(c<'0' || c>'9'){
					throw new InputMismatchException();}
				res *= 10;
				res += c - '0';
				c = read();
			} while(!isSpaceChar(c));
			return res*sgn;
		}

		public long nextLong(){
			int c = read();
			while(isSpaceChar(c))
				c = read();
			int sgn = 1;
			if(c == '-'){
				sgn = -1;
				c = read();
			}
			long res = 0;
			do{
				if(c<'0' || c>'9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while(!isSpaceChar(c));
			return res*sgn;
		}

		public String next(){
			int c = read();
			while(isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c = read();
			}while(!isSpaceChar(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c){
			if(filter != null)
				return filter.isSpaceChar(c);
			return c==' ' || c=='\n' || c=='\r' || c=='\t' || c==-1;
		}

		public interface SpaceCharFilter{
			public boolean isSpaceChar(int ch);
		}
	}

}


import java.util.*;
import java.io.*;

public class StraightA {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw;
        StringTokenizer st;

        st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());

        int[] marks = new int[n];
        st = new StringTokenizer(br.readLine());

        double avg = 0;
        for (int i=0; i<n; i++) {
            avg += Integer.parseInt(st.nextToken());
        }

        avg /= n;
        int ans =0;
        while (Math.round(avg) < k) {

            avg = avg + k*1.0/++n;
            ++ans;
        }
        pw = new PrintWriter(System.out);
        pw.println(ans);
        pw.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Straight {
	static int n, k, marks[];
	static double result, totaleMark = 0, times = 0;

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tk;
		String line = in.readLine();
		tk = new StringTokenizer(line);
		n = getInt(tk.nextToken());
		k = getInt(tk.nextToken());
		marks = new int[n];
		line = in.readLine();
		tk = new StringTokenizer(line);

		for (int i = 0; i < n; i++) {
			totaleMark+ = getInt(tk.nextToken());

		}
		times = n;
		double r = totaleMark / times;

		if (Math.round(r) >= k) {
			System.out.println("0");
		} else {
			hack();
		}

	}

	static void hack() {

		while (times < 20) {
			totaleMark += k;
			times++;
			double r = totaleMark / times;
			if (Math.round(r) >= k) {
				System.out.println((int) (times - n));
				return;
			}

		}
	}

	static int getInt(String s) {
		try {
			return Integer.parseInt(s);

		} catch (Exception e) {
			System.out.println(s + " : is not an Integer");
			return 0;
		}
	}
}


import java.util.*;

public class NewClass6 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int scores = in.nextInt();
        int high = in.nextInt();
        in.nextLine();
        double[] score = new double[scores];
        for (int i = 0; i < scores; i++) {
            score[i] = in.nextDouble();
        }
        in.nextLine();

        System.out.println(addition(score, scores, high));

    }

    public static int addition(double[] score, int scores, int high) {
            double total = 0;
            double avg = 0;
            int temp = scores;
            for (int i = 0; i < score.length; i++) {
                total += score[i];
            }
        if ((total+high) / ++scores > high-0.5) {
            return 1;
        } else {
            avg = total/scores;
import java.util.*;

public class NewClass6 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int scores = in.nextInt();
        double high = in.nextDouble();
        in.nextLine();
        double[] score = new double[scores];
        for (int i = 0; i < scores; i++) {
            score[i] = in.nextDouble();
        }
        in.nextLine();

        System.out.println(addition(score, scores, high));

    }

    public static int addition(double[] score, int scores, double high) {
        double total = 0;
        int temp=scores;
        for (int i = 0; i < score.length; i++) {
            total += score[i];
        }
        double avg = total/scores;
        if (avg > high - 0.5) {
            return 0;
        } else {
        while (avg < high-0.5) {
            total += high;
            scores++;
            avg = total/(double)scores;
        }
        return scores-temp;
        }
    }
}

            while (avg < high - 0.5) {
                total += high;
                scores++;
                avg = total / scores;
            }
            return scores - temp;
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class TestOOP extends MainOOP {

    public static void main(String[] args) {

        try {
            BufferedReader br
                    = new BufferedReader(new InputStreamReader(System.in));
            StringTokenizer st= new StringTokenizer(br.readLine());
            int a=Integer.parseInt(st.nextToken());
            int b=Integer.parseInt(st.nextToken());
            int[] seg={6,2,5,5,4,5,6,4,7,6};
            int sum=0; int r=0,l=0;
            for (int i = a; i <=b; i++) {
                r=i;
                while(r>0){
                    l= r%10 ;
                    r= r/10  ;
                   sum+= seg[l] ;

                }

            }
            System.out.println(sum);

        } catch (Exception e) {
        }

    }
}


import java.util.*;
import java.io.*;

public class Solution {
    static int[] digitSegments = new int[] { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

    static int countSegments(int n) {
        int segments = 0;
        while(n > 0) {
            segments += digitSegments[n % 10];
            n /= 10;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int segments = 0;
        for (int i = a; i <= b; ++i) {
            segments += countSegments(i);
        }
        System.out.println(segments);
    }
}


public class CodeForces {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1,x2;
		int counter=0;
		int segment[] = {6,2,5,5,4,5,6,3,7,6};
		x1=sc.nextInt();
		x2=sc.nextInt();
		for (int i = x1; i <= x2; i++) {
			int temp=i;
			while(temp!=0){
				counter += segment[temp%10];
				temp/=10;
			}
		}
		System.out.println(counter);
	}
}


//package codeforce;

import java.util.HashMap;
import java.util.Scanner;

/* @author Kbk*/
public class Calculator{
    HashMap<Integer,Integer> has=new HashMap();
    public void solve(){
        has.put(0,6);
        has.put(1,2);
        has.put(2,5);
        has.put(3,5);
        has.put(4,4);
        has.put(5,5);
        has.put(6,6);
        has.put(7,3);
        has.put(8,7);
        has.put(9,6);
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int segments=0;
        for(int i=a;i<=b;i++){
            int len=String.valueOf(i).length();
            int data=i;
            for(int j=0;j<len;j++){
                int mod=data%10;
                segments=segments+(int)has.get(mod);
                data=data/10;
            }
        }
        System.out.println(segments);
    }
}
public class SevenSegments {
    public static void main(String[] args) {
        new Calculator().solve();
    }
}


import java.util.*;
public class coins
{
    public static void main(String args[])
    {
        Scanner s=new Scanner();
        int n,S,count=0;
        n=s.nextInt();
        S=s.nextInt();
        count=S/n;
        count++;
        System.out.println(count);

    }
}


import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int s=s.nextInt();
		System.out.println(s/n + s%n);
	}

}


import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System. in);
        int n=scanner.readInt();
        int s=scanner.readInt();
        if(s<=n){
            System.out.print1n("1");
        }
        else
        System.out.println(s%n+s/n);
    }
}


import java.util.Scanner;
public class A {
    public static void main(String... args) {
        Scanner s = new Scanner(System.in);
        int n, s;
        n = s.nextInt();
        s = s.nextInt();

        System.out.println(s/n+1);
    }
}


import java.io.*;
import java.util.*;
import java.math.BigInteger;
/*
 * This file was created by ayush in attempt to solve the problem problems
 */
public class main {
    public void solve(int n, PrintWriter out) {
	int ans=0;
	for(int i = 1; i < Math.pow(2,10); i++)
  	{
    		String format="%0"+n+"d";
		String tmp="";
    		tmp=String.format(format,Integer.valueOf(Integer.toBinaryString(i)));
		long IntegerCon =Long.parseInt(tmp);

    		if(IntegerCon<=n){
			ans++;
		}
  	}
	out.println(ans);
    }

    public static void main(String[] args) throws Exception {

        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();

        Date t1 = new Date();
        main solver = new main();

        solver.solve(n, out);
        out.flush();

        Date t2 = new Date();
        System.err.println(String.format("Your program took %f seconds", (t2.getTime() - t1.getTime()) / 1000.0));
        out.close();

    }
    static class FastScanner {

    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    public FastScanner(InputStream in) throws Exception {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = new StringTokenizer(reader.readLine().trim());
    }

    public int numTokens() throws Exception {
        if (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine().trim());
            return numTokens();
        }
        return tokenizer.countTokens();
    }

    public boolean hasNext() throws Exception {
        if (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine().trim());
            return hasNext();
        }
        return true;
    }

    public String next() throws Exception {
        if (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine().trim());
            return next();
        }
        return tokenizer.nextToken();
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }

    public float nextFloat() throws Exception {
        return Float.parseFloat(next());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }

    public int[] nextIntArray() throws Exception {
        String[] line = reader.readLine().trim().split(" ");
        int[] out = new int[line.length];
        for (int i = 0; i < line.length; i++) {
            out[i] = Integer.valueOf(line[i]);
        }
        return out;
    }

    public double[] nextDoubleArray() throws Exception {
        String[] line = reader.readLine().trim().split(" ");
        double[] out = new double[line.length];
        for (int i = 0; i < line.length; i++) {
            out[i] = Double.valueOf(line[i]);
        }
        return out;
    }

    public Integer[] nextIntegerArray() throws Exception {
        String[] line = reader.readLine().trim().split(" ");
        Integer[] out = new Integer[line.length];
        for (int i = 0; i < line.length; i++) {
            out[i] = Integer.valueOf(line[i]);
        }
        return out;
    }

    public BigInteger[] nextBigIngtegerArray() throws Exception {
        String[] line = reader.readLine().trim().split(" ");
        BigInteger[] out = new BigInteger[line.length];
        for (int i = 0; i < line.length; i++) {
            out[i] = new BigInteger(line[i]);
        }
        return out;
    }

    public String nextLine() throws Exception {
        return reader.readLine().trim();
    }

    public BigInteger nextBigInteger() throws Exception {
        return new BigInteger(next());
    }
    }

    static class DEBUG {
        public static void DebugInfo(String disp) {
            System.err.println("DEBUG Info: " + disp);
        }

        public static void DebugVariable(String variable, String value) {
            System.err.println("DEBUG Info: " + variable + " => " + value);
        }

        public static void DebugVariable(String variable, int value) {
            System.err.println("DEBUG Info: " + variable + " => " + value);
        }

        public static void DebugVariable(String variable, long value) {
            System.err.println("DEBUG Info: " + variable + " => " + value);
        }

        public static void DebugArray(int[] value) {
            for (int i = 0; i < value.length; i++) {

                System.err.println("DEBUG Info: " + i + " => " + value[i]);
            }
        }

    }

}


import java.util.Scanner;

public class JavaApplication15 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
	String s = in.nextLine();
	int total=0;
	for(int i=0;i<s.length();i++)
        {
            if(s.charAt(i)=='1')
                {
                    total=total+(int)Math.pow(2,s.length()-i-1);
                }
		else if(s.charAt(i)>'1')
                {
			total=total+(int)Math.pow(2, s.length()-i)-1;
			break;
		}
	}
	System.out.println(total);


import java.util.*;
public class Main {
  static int ans=0;
  static int n=0;
  static int k=0;
  public static void fun(int n)
  {
    if(n==0)
    return;
    int k=n;
    while(k>0)
    {
      if(k%10>1)
      break;
      k=k/10;
    }
    if(k==0)
    ans++;
    fun(n-1);
  }
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    n = s.nextInt();
    fun(n);
    System.out.println(ans);
  }
}


import java.util.Scanner;

public class RunningStudent {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();
        for(int i=1; i<=1<<9; i++) {
            String bin = Integer.toBinaryString(i);
            int ii = Integer.parseInt(bin);
            if(ii > input) {
                System.out.println(i-1);
                return;
            }
        }
    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class solveC {
	public static void main(String[] args) throws IOException {
		Scanner f = new Scanner(System.in);
		StringTokenizer st = new StringTokenizer(f.nextLine());

		double p = Double.parseDouble(st.nextToken());
		double q = Double.parseDouble(st.nextToken());

		double A = p / q;
		int N = 20000000;
		boolean[] isPrime = new boolean[N + 1];
		for (int i = 2; i <= N; i++) {
			isPrime[i] = true;
		}
		for (int i = 2; i * i <= N; i++) {
			if (isPrime[i]) {
				for (int j = i; i * j <= N; j++) {
					isPrime[i * j] = false;
				}
			}
		}

		int ans = 0;

		int[] pi = new int[N + 1];
		int[] rub = new int[N + 1];

		for (int i = 1; i <= N; i++) {
			pi[i] = pi[i - 1];
			rub[i] = rub[i - 1];
			if (isPrime[i]) {
				pi[i]++;
			}
			if (isPalindrome(i))
				rub[i]++;

			double pibyrub = (((double) pi[i]) / rub[i]);
			if (pibyrub <= A) {
				ans = i;
			}

		}
		if (ans == 0)
			System.out.println("Palindromic tree is better than splay tree");
		else
			System.out.println(ans);

	}

	public static int gcd(int p, int q) {
		if (q == 0) return p;
		else return gcd(q, p % q);
	}

	public static boolean isPalindrome(int x) {
		String g = Integer.toString(x);
		return g.equals(new StringBuilder(g).reverse().toString());
	}
}


import java.io.*;
import java.util.*;

public class palindrome {
	public static void main(String args[]) throws Exception {
		Scanner in = new Scanner(new File(System.in));
		int p = in.nextInt(), q = in.nextInt();
		int n = 1200000;
		boolean[] arr = new boolean[n];
		int[] pi = new int[n];
		int[] pal = new int[n];
		pi[0] = 0;
		pi[1] = 0;
		pal[0] = 0;
		pal[1] = 1;
		for (int i = 0; i < n; i++) {
			arr[i] = true;
		}
		arr[0] = false;
		arr[1] = false;
		for (int i = 2; i < n; i++) {
			pi[i] = pi[i - 1];
			pal[i] = pal[i - 1] + isPalindrome(i);
			if (arr[i] && (long) i * i < n) {
				for (int j = i * i; j < n; j += i) {
					arr[j] = false;
				}
			}
			if (arr[i]) pi[i]++;
		}
		int a = 0;
		for (int i = 1; i < n; i++) {
			if (pi[i] <= p * pal[i] / q) a = i;
		}
		System.out.println(a);
	}
	public static int isPalindrome(int n) {
		String str = n + "";
		for (int i = 0; i < str.length() - 1; i++) {
			if (str.charAt(i) != str.charAt(str.length() - i - 1)) {
				return 0;
			}
		}
		return 1;
	}
}