import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class ComputerGame3 {

	static double[][] identity;
	static double INF = 1e18D;
	static int MAXPOW = 39;
	public static void main(String[] args) {
		FS in = new FS();
		PrintWriter out = new PrintWriter(System.out);
		int N = in.nextInt();
		long T = in.nextLong();
		double[] A = new double[N];
		double[] B = new double[N];
		double[] P = new double[N];
		double[] PA = new double[N];
		double V = 0;
		for(int i = 0; i < N; i++) {
			A[i] = in.nextDouble();
			B[i] = in.nextDouble();
			P[i] = in.nextDouble();
			PA[i] = P[i]*A[i];
			V = Math.max(V, P[i]*B[i]);
		}

		ConvexHullLinear cht = new ConvexHullLinear(N, -1, 0, true);
		Integer order[] = new Integer[N];
		for(int i = 0; i < N; i++) order[i] = i;
		Arrays.sort(order, (a,b) -> {
			if(P[a] == P[b]) return -Double.compare(PA[a], PA[b]);
			return Double.compare(P[a], P[b]);
		});
		for(int i = N-1; i >= 0; i--) {
			int id = order[i];
			cht.add(P[id], PA[id], id);
		}
		identity = identity(3);

//		for(int i = 0; i <= cht.s; i++) System.out.print(cht.is[i]+" ");
//		System.out.println();

		double vec[][] = new double[][]{{0}, {0}, {1}}; //prevDp, prevT, prev1
		for(int l = cht.s; l >= 0; l--) {
			double stopAt = l == 0 ? INF : cht.intersect(l, l-1);
			int id = cht.is[l];

			double mat[][] = new double[][] {
				{1-P[id], P[id]*V, P[id]*A[id]},
				{0, 1, 1},
				{0, 0, 1},
			};

			double matToPowerOf2[][][] = new double[MAXPOW][][];
			matToPowerOf2[0] = identity;
			matToPowerOf2[1] = mat;
			for(int i = 2; i < MAXPOW; i++) matToPowerOf2[i] = mult(matToPowerOf2[i-1], matToPowerOf2[i-1]);

			// Find how long we will use this line for
			double cur[][] = identity;
			for(int i = MAXPOW-1; i >= 0; i--) {
				double next[][] = mult(cur, matToPowerOf2[i]);
				double nextVec[][] = mult(next, vec);

				long t = (long)(Math.round(nextVec[1][0]));
				double dpt = nextVec[0][0];
				double prevDp = (dpt-P[id]*V*(t-1)-P[id]*A[id])/(1-P[id]);
				double lastQuery = V*(t-1)-prevDp;

				boolean bad = (t > T) || (lastQuery > stopAt);
				if(!bad) {
					// Take this expo
					cur = next;
				}
			}
			vec = mult(cur, vec);
		}
		System.out.println(vec[0][0]);
	}

	static void print(double a[][]) {
		for(int i = 0; i < a.length; i++) {
			System.out.println(Arrays.toString(a[i]));
		}
		System.out.println();
	}

	static double [][] pow(double m[][], long p) {
		if(p == 0) return identity;
		if(p == 1) return m;
		if((p&1) == 0) {
			double res[][] = pow(m, p>>1);
			return mult(res,res);
		}
		else {
			return mult(m, pow(m, p-1));
		}
	}

	static double[][] mult(double a[][], double b[][]){
		double res[][] = new double[a.length][b[0].length];
		for(int i = 0; i < a.length; i++) {
			for(int j = 0; j < b[0].length; j++) {
				for(int k = 0; k < a[i].length; k++) {
					res[i][j] += a[i][k]*b[k][j];
				}
			}
		}
		return res;
	}
	static double[][] identity(int sz) {
		double res[][] = new double[sz][sz];
		for(int i = 0; i < sz; i++) res[i][i] = 1;
		return res;
	}

	/*Linear version of Convex hull optimization. Written by Joshua Fair
	Constructor(a, b, c, d):
	a = max number of lines that will be added
	b = 1 if lines are added in increasing order and -1 if added in decreasing order
	c =
		-1 if points are queried in order from large X to small X
		0 if the query points are in no specific order
		1 if the points are queries in order from small X to large X
	d = true if the queries are max, and false if the queries are min
	!!! If you add lines in one order and query points in the opposite order, it will only be linear if all lines are
	added before any points are queried !!!
	*/
	static class ConvexHullLinear{
		boolean upd, isMin;
		int type, inc, s, p;
		double[] ms,bs;
		int[] is;
		public ConvexHullLinear(int numLines, int ii, int tt, boolean mm) {
			s = -1;
			p = 0;
			ms = new double[numLines];
			bs = new double[numLines];
			is = new int[numLines];
			inc = ii;
			type = tt;
			isMin = !mm;
			upd = false;
			if(isMin) inc = -inc;
		}
		public void add(double m, double b, int i) {
			if(isMin) { m=-m; b=-b; }
			upd = true;
			s++;
			ms[s] = m;
			bs[s] = b;
			is[s] = i;
			while((s > 0 && ms[s] == ms[s-1] && bs[s] >= bs[s-1])
					|| (s-2 >= 0 && bad(s-2,s-1,s))) {
				ms[s-1] = m;
				bs[s-1] = b;
				is[s-1] = i;
				s--;
			}
		}
		public boolean bad(int l1, int l2, int l3) {
			if(inc == 1) return intersect(l2,l3) <= intersect(l1,l2);
			return intersect(l2,l3) >= intersect(l1,l2);
		}
		public boolean eqq(int l1, int l2) {
			return eq(ms[l1], ms[l2]) && eq(bs[l1], bs[l2]);
		}
		public boolean eq(double a, double b) {
			return Math.abs(a-b) < 1e-10;
		}
		public double intersect(int l1, int l2) {
			return (double)(bs[l2]-bs[l1])/(double)(ms[l1]-ms[l2]);
		}
		public double eval(int l1, double x) {
			return ms[l1]*x + bs[l1];
		}
	}

	static class FS{
		BufferedReader br;
		StringTokenizer st;
		public FS() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while(st == null || !st.hasMoreElements()) {
				try { st = new StringTokenizer(br.readLine());}
				catch(Exception e) { throw null;}
			}
			return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next());}
		double nextDouble() { return Double.parseDouble(next());}
		long nextLong() { return Long.parseLong(next());}
	}

}


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

public class Main
{

    static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

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

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

		public int ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nia(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = ni();
			}
			return a;
		}

		public String rs() {
			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 String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

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

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

	}

    static long mod=1000000007;
    static BigInteger bigInteger = new BigInteger("1000000007");
    static int n = (int)1e6;
    static boolean[] prime;
    static ArrayList<Integer> as;
    static void sieve() {
			Arrays.fill(prime	, true);
			prime[0] = prime[1] = false;
			for(int i = 2 ; i * i <= n ; ++i) {
				if(prime[i]) {
					for(int k = i * i; k< n ; k+=i) {
						prime[k] = false;
					}
				}
			}

		}

    public static void main(String[] args)
    {

        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        //prime  = new boolean[n + 1];
		//sieve();
		//prime[1] = false;
		/*
		as = new ArrayList<>();
		for(int i=2;i<=1000000;i++)
		{
		    if(prime[i])
		    as.add(i);
		}
		*/

       /*

	long a = sc.nl();

            BigInteger ans = new BigInteger("1");
            for (long i = 1; i < Math.sqrt(a); i++) {
                if (a % i == 0) {
                    if (a / i == i) {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));

                    } else {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));
                        ans = ans.multiply(BigInteger.valueOf(phi(a / i)));

                    }

                }
            }
            w.println(ans.mod(bigInteger));

            */
        long m = sc.nl();
        int one = 0;
        long res = 0;
        int temp = 0;
        int zero = 0;
        for(long i = m;i>=1;i--)
        {
            if(m % i == 0)
            {
                one = 0;
                zero = 0;
                temp = 0;
               String s = Long.toBinaryString(i);
               for(int j=0;j<s.length();j++)
               {
                   if(s.charAt(j)=='1')
                   {
                       one++;
                   }

                   else
                   {
                       temp = j;
                       break;
                   }

               }
               for(int j=temp;j<s.length();j++)
               {
                   if(s.charAt(j)=='0')
                   {
                       zero++;
                   }

                   else
                   {

                       break;
                   }

               }

               if(one + zero == s.length() && one == zero+1)
               {
                   res = i;
                   break;
               }

            }

        }
        w.println(res);

w.close();

    }

     public static long modMultiply(long one, long two) {

		return (one % mod * two % mod) % mod;
	}
    static long fx(int m)
    {
        long re = 0;
        for(int i=1;i<=m;i++)
        {
            re += (long) (i / gcd(i,m));
        }
        return re;
    }
     static long gcd(long a, long b)
    {
	 if (a == 0)
	  return b;

	return gcd(b%a, a);
    }

     static long phi(long nx)
    {
        // Initialize result as n
        double result = nx;

        // Consider all prime factors of n and for
        // every prime factor p, multiply result
        // with (1 - 1/p)
        for (int p = 0; as.get(p) * as.get(p) <= nx; ++p)
        {
            // Check if p is a prime factor.
            if (nx % as.get(p) == 0)
            {
                // If yes, then update n and result
                while (nx % as.get(p) == 0)
                    nx /= as.get(p);
                result *= (1.0 - (1.0 / (double) as.get(p)));
            }
        }

        // If n has a prime factor greater than sqrt(n)
        // (There can be at-most one such prime factor)
        if (nx > 1)
            result *= (1.0 - (1.0 / (double) nx));

        return (long)result;

        //return(phi((long)result,k-1));

    }

    public static int primeFactors(int n)
    {
        int sum = 0;
        // Print the number of 2s that divide n
        while (n%2==0)
        {
            sum = 1;
            //System.out.print(2 + " ");
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {

               // System.out.print(i + " ");
                n /= i;
            }
            sum++;
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2)
            sum++;
            return sum;
    }
    static int digitsum(int x)

    {

        int sum = 0;
        while(x > 0)
        {
            int temp = x % 10;
            sum += temp;
            x /= 10;
        }
        return sum;

    }
    static int countDivisors(int n)
    {
        int cnt = 0;
        for (int i = 1; i*i <=n; i++)
        {
             if (n % i == 0 && i<=1000000)
             {
                // If divisors are equal,
                // count only one
                if (n / i == i)
                   cnt++;

                else // Otherwise count both
                    cnt = cnt + 2;
             }
         }
        return cnt;
    }

    static boolean isprime(int n)
    {

    if(n == 2)
        return true;
    if(n == 3)
        return true;
    if(n % 2 == 0)
        return false;
    if(n % 3 == 0)
        return false;

    int i = 5;
   int w = 2;

    while(i * i <= n)
    {
        if(n % i == 0)
            return false;

        i += w;
        w = 6 - w;
    }

    return true;
    }

    static long log2(long value) {
    return Long.SIZE-Long.numberOfLeadingZeros(value);
}

    static int binarysearch(int []arr,int p,int n)
    {

        int st = 0;
        int end = n-1;
        int mid = (st + end)/2;
        int temp = 0;
        while(st < end)
        {
            mid = (st + end)/2;

            if(p > arr[mid])
            {
                st = mid+1;

            }
            else if(p < arr[mid])
            {
                end = mid;

            }
            else if(p == arr[mid])
            {
            temp = mid;
            break;
            }

        }
        if(st == end)
        temp = st;

        return temp;
    }

    static class Student
    {

        int floor;
        int time;
        Student(int floor,int time)
        {
            this.floor = floor;
            this.time = time;

        }

    }

    public static int ip(String s){
		return Integer.parseInt(s);
	}
	 public static String ips(int s){
		return Integer.toString(s);
	}

}


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

public class Main {
    static BufferedReader newInput() throws IOException {
        return new BufferedReader(new InputStreamReader(System.in));
    }
    static PrintWriter newOutput() throws IOException {
        return new PrintWriter(System.out);
    }
    public static void main(String[] args) throws IOException {
        BufferedReader in = newInput();
        PrintWriter out = newOutput();
        function(in, out);
        out.flush();
    }
    public static void function(BufferedReader in, PrintWriter out) throws IOException {
        //StringTokenizer t = new StringTokenizer(in.readLine());
        String[] nk = in.readLine().split(" ");
        long n = Integer.parseInt(nk[0]);
        long k = Long.parseLong(nk[1]);

        ArrayList<Integer> nums = new ArrayList<>();
        for (int i = Math.max(1, (int)n-13); i <= (int)n; i++) {
            nums.add(i);
        }

        long fact = factorial(Math.min(n, 14));
        long x = Math.min(n, 14);
        int lucks = lucks(Math.max(1, (int)n-13));

        for (int i = Math.max(1, (int)n-13); i <= n; i++) {
            fact /= x;
            x--;
            int b = (int)((k-1)/fact);
            if (b >= n){
                out.println("-1");
                return;
            }
            k -= (b*fact);
            int num = nums.get(b);
            nums.remove(b);
            if (isLucky(num) && isLucky(i)){
                lucks++;
            }
        }
        out.println(lucks);
    }
    public static long factorial(long num){
        long x = num;
        num--;
        for (;num != 0; num--) {
            x *= num;
        }
        return x;
    }
    public static boolean isLucky(int x){
        for (; x != 0; x /= 10) {
            int b = x % 10;
            if (b != 7 && b != 4){
                return false;
            }
        }
        return true;
    }
    public static int lucks(int max){
        int lucks = 0;
        ArrayList<Integer> luckys = new ArrayList<>();
        luckys.add(4);
        luckys.add(7);
        for (int i = 0; i < 8; i++) {
            luckys = add(luckys);
        }
        for (int i : luckys) {
            if (i < max){
                lucks++;
            }
        }
        return lucks;
    }
    public static int prev = 0;
    public static ArrayList<Integer> add(ArrayList<Integer> lucks){
        int len = lucks.size();
        for (int i = prev; i < len; i++) {
            lucks.add(lucks.get(i)+(int)(4*Math.pow(10, String.valueOf(lucks.get(i)).length())));
        }
        for (int i = prev; i < len; i++) {
            lucks.add(lucks.get(i)+(int)(7*Math.pow(10, String.valueOf(lucks.get(i)).length())));
        }
        prev = len;
        return lucks;
    }
}


import java.util.Scanner;

public class T1 {

	public static void main(String[] args) {
		Scanner jk=new Scanner(System.in);
		int n=jk.nextInt();
		int[] arr=new int[100];
		for (int i=0;i<n;i++){
			int tmp=jk.nextInt();
			arr[tmp-1]++;
		}
		boolean flag=false;
		int res1=0;
		int res2=0;
		for (int i=0;i<100;i++){
			for (int j=0;j<100;j++){
				if ((arr[i]==arr[j])&&(arr[i]!=0)&&(i!=j)){
					flag=true;
					res1=i+1;
					res2=j+1;
					break;

				}
			}
		}
		jk.close();

		if (flag){
			if (arr[res1-1]+arr[res2-1]!=n)
			{
				System.out.println("NO");
			}
			else
		{
			System.out.println("YES");
			System.out.println(res1+" "+res2);}}
		else{
			System.out.println("NO");
		}
	}

}


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

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

	long n,k;

	public Main() throws Exception{
		Scanner sc = new Scanner(System.in);
//		Scanner sc = new Scanner(new FileReader("input"));
		n = sc.nextLong();
		k = sc.nextLong();
		if ( k==0){
			System.out.println("0 0");
			sc.close();
			return;
		}

		System.out.println( Math.min(1, n-k) + " " + Math.min(k*2, n-k));

        sc.close();
	}

	static long gcd(long a, long b)
	{
	    while (b > 0)
	    {
	        long temp = b;
	        b = a % b;
	        a = temp;
	    }
	    return a;
	}

	static long lcm(long a, long b) {
	    return a * (b / gcd(a, b));
	}

}


import java.util.Scanner;

//import TetraHedron.Scanner;

public class SquaresandSegements {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);
		long n = input.nextLong();
		long val = (long)Math.sqrt(n);
		long total = 2*val;
	//	System.out.println(total);
		long rem = n - (long)Math.pow((long)Math.sqrt(n),2);
		///System.out.println(rem);
		total += (long)Math.ceil(rem/Math.sqrt(n));
		System.out.println(total);
	}

}


import java.util.Scanner;

/**
 * B. File Name
 * @author satyam
 *uxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxxxxmrx
 */
public class CodeForces16 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a= Integer.parseInt(sc.nextLine());
		String str=sc.nextLine();
		int res=0,counter=0;
		for(int i=0;i<a;i++) {
			if(str.charAt(i)=='x') {
				counter++;
			}else if(counter>2){
				res+=(counter-2);
				counter=0;
			}else {
				counter=0;
			}
		}
		if(counter>2) res+=(counter-2);
		System.out.println(res);
	}
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        char[] c = s.toCharArray();

        char a = 'a';

        int total = 0;

        for (int i = 0; i < c.length; i++) {
            if (Math.abs(c[i] - a) <= 13) {
                total += Math.abs(c[i] - a);
                a = c[i];
            }else{
                total += 26 - Math.abs((c[i] - a));
                a = c[i];
            }
        }

        System.out.println(total);

    }
}

//https://codeforces.com/problemset/problem/731/A


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

import static java.lang.Math.*;

public class Main implements Runnable {

	int s;
	int c3 = 0, c4 = 0, c5 = 0;

	int f(int k3, int k4) {
		int k5 = (s - k3 * c3 - k4 * c4) / c5;
		return abs(c3 * k3 - c4 * k4) + abs(c4 * k4 - c5 * k5);
	}

	void solve() throws Exception {
		int n = sc.nextInt();
		s = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int mark = sc.nextInt();
			if (mark == 3) {
				c3++;
			} else if (mark == 4) {
				c4++;
			} else if (mark == 5) {
				c5++;
			}
		}
		ArrayList<Integer>[] may = new ArrayList[c5];
		for (int i = 0; i < c5; i++) {
			may[i] = new ArrayList<Integer>();
			for (int j = 0; j < c5; j++) {
				if ((c3 * i + c4 * j) % c5 == s % c5) {
					may[i].add(j);
				}
			}
		}
		int bestk3 = -1, bestk4 = -1, bestk5 = -1;
		int bestf = Integer.MAX_VALUE / 2;
		for (int k3 = 0; k3 * c3 <= s; k3++) {
			if (may[k3 % c5].size() == 0) {
				continue;
			}
			ArrayList<Integer> cmay = may[k3 % c5];
			int ll = -1, rr = 500000;
			while (rr - ll > 1) {
				int mm = (ll + rr) / 2;
				int valm = cmay.get(mm % cmay.size()) + mm / cmay.size() * c5;
				if (valm < k3) {
					ll = mm;
				} else {
					rr = mm;
				}
			}
			int l = rr;
			ll = -1;
			rr = 500000;
			while (rr - ll > 1) {
				int mm = (ll + rr) / 2;
				long valm = cmay.get(mm % cmay.size()) + mm / cmay.size() * c5;
				if ((s - k3 * c3 - valm * c4) >= c5 * valm) {
					ll = mm;
				} else {
					rr = mm;
				}
			}
			int r = ll;
			if (l > r) {
				continue;
			}
			while (r - l >= 3) {
				int m1 = l + (r - l) / 3;
				int m2 = r - (r - l) / 3;
				int f1 = f(k3, cmay.get(m1 % cmay.size()) + m1 / cmay.size() * c5);
				int f2 = f(k3, cmay.get(m2 % cmay.size()) + m2 / cmay.size() * c5);
				if (f1 >= f2) {
					l = m1;
				} else {
					r = m2;
				}
			}
			for (int i = l; i <= r; i++) {
				int k4 = cmay.get(i % cmay.size()) + i / cmay.size() * c5;
				int k5 = (s - k3 * c3 - k4 * c4) / c5;
				int fi = f(k3, k4);
				if (fi < bestf) {
					bestk3 = k3;
					bestk4 = k4;
					bestk5 = k5;
					bestf = fi;
				}
			}
		}
		if (bestk3 != -1) {
			out.println(bestk3 + " " + bestk4 + " " + bestk5);
		} else {
			out.println(-1);
		}
	}

	BufferedReader in;
	PrintWriter out;
	FastScanner sc;

	static Throwable uncaught;

	@Override
	public void run() {
		try {
			//System.setOut(new PrintStream("test.txt"));
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable t) {
			Main.uncaught = t;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread t = new Thread(null, new Main(), "", 128 * 1024 * 1024);
		t.start();
		t.join();
		if (uncaught != null) {
			throw uncaught;
		}
	}

}

class FastScanner {

	BufferedReader reader;
	StringTokenizer strTok;

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

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

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

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

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

}


import java.io.*;
import java.util.*;
public class wolf{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		sc.nextLine();
		char arr[][]=new char[15][15];
		for(int i=0;i<n;i++)
		{
			String data=sc.nextLine();
			for(int j=0;j<m;j++)
			{
				arr[i][j]=data.charAt(j);
				//sc.nextLine();
			}
		}
		int k=0;

		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(arr[i][j]=='W')
				{
					if( i>0 &&arr[i-1][j]=='P'  )
					{
						arr[i-1][j]='.';
						k++;
					}
					else if((i+1)<n&& arr[i+1][j]=='P')
					{
						arr[i+1][j]='.';
						k++;
					}
					else if(j>0&&arr[i][j-1]=='P' )
					{
						arr[i][j-1]='.';
						k++;
					}
					else if((j+1)<m&&arr[i][j+1]=='P' )
					{
						arr[i][j+1]='.';
						k++;
					}
				}
			}
		}
		System.out.println(k);
	}
}


import java.util.*;
import java.io.*;
import java.io.File;
import java.util.AbstractSet;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Hello {

  public static void main(String[] args) {
    //try {
    //  FileInputStream fis = new FileInputStream("data.txt");
    //  System.setIn(fis);
      Scanner in = new Scanner(System.in);

      int n = in.nextInt();
      System.out.println(n / 2 + 1);

    //} catch (FileNotFoundException e){
    //  System.out.println("error");
    //}
  }
}


import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    static class Point {
        int x;
        int y;
        int index;

        Point(int x, int y, int index) {
            this.x = x;
            this.y = y;
            this.index = index;
        }
    }

    static class GraphNode implements Comparable<GraphNode> {
        int sideId;
        int x;
        double y;
        double distance = 1e100;
        boolean mark = false;

        List<GraphNode> outgo = new ArrayList<GraphNode>();

        GraphNode(int sideId, int x) {
            this.sideId = sideId;
            this.x = x;
        }

        public boolean equals(Object o) {
            if (this == o) return true;
            GraphNode graphNode = (GraphNode) o;

            if (sideId != graphNode.sideId) return false;
            if (x != graphNode.x) return false;

            return true;
        }

        public int hashCode() {
            int result = sideId;
            result = 31 * result + x;
            return result;
        }

        public int compareTo(GraphNode graphNode) {
            int z = sideId - graphNode.sideId;
            if (z != 0) return z;
            return x - graphNode.x;
        }
    }

    List<GraphNode> nodes = new ArrayList<GraphNode>();
    Map<GraphNode, GraphNode> canonical = new HashMap<GraphNode, GraphNode>();

    static class Edge implements Comparable<Edge> {
        Point v1;
        Point v2;
        int isUpper;

        Edge(Point v1, Point v2) {
            if (v1.x > v2.x) {
                Point tmp = v1;
                v1 = v2;
                v2 = tmp;
            }
            this.v1 = v1;
            this.v2 = v2;
        }

        public int compareTo(Edge edge) {
            int minx = Math.max(v1.x, edge.v1.x);
            int maxx = Math.min(v2.x, edge.v2.x);
            if (minx >= maxx) {
                throw new RuntimeException();
            }
            //if (this.v1 == edge.v1 && this.v2 == edge.v2) return 0;
            int mid = (minx + maxx) / 2;
            long diff = ((mid - v1.x) * (long) (v2.y - v1.y) + v1.y * (long) (v2.x - v1.x)) * (edge.v2.x - edge.v1.x)
                    - ((mid - edge.v1.x) * (long) (edge.v2.y - edge.v1.y) + edge.v1.y * (long) (edge.v2.x - edge.v1.x)) * (v2.x - v1.x);
            return Long.signum(diff);
        }
    }

    int n;

	public void solve(int testNumber, InputReader in, PrintWriter out) {
        Random random = new Random(5943715431L);
        n = in.nextInt();
        Point[] poly = new Point[n];
        for (int i = 0; i < n; ++i) {
            int x = in.nextInt();
            int y = in.nextInt();
            poly[i] = new Point(x * 2, y * 2, i);
        }
        for (int i = 0; i < poly.length; ++i) {
            Edge e1 = new Edge(poly[i], poly[(i + 1) % poly.length]);
            Edge e2 = new Edge(poly[i], poly[(i + poly.length - 1) % poly.length]);
            addTransition(e1, e2, poly[i].x);
            addTransition(e2, e1, poly[i].x);
        }
        int s = in.nextInt() - 1;
        int t = in.nextInt() - 1;
        TreeSet<Edge> picture = new TreeSet<Edge>();
        Point[] polyByX = poly.clone();
        for (int i = 0; i < polyByX.length; ++i) {
            int j = i + random.nextInt(polyByX.length - i);
            Point tmp = polyByX[i];
            polyByX[i] = polyByX[j];
            polyByX[j] = tmp;
        }
        Arrays.sort(polyByX, new Comparator<Point>() {
            public int compare(Point a, Point b) {
                int z = Integer.signum(a.x - b.x);
                if (z != 0) return z;
                return Integer.signum(a.y - b.y);
            }
        });
        for (int pi = 0; pi < polyByX.length;) {
            int pj;
            Point prevP = null;
            for (pj = pi; pj < polyByX.length && polyByX[pj].x == polyByX[pi].x; ++pj) {
                Point p = polyByX[pj];
                Point a = poly[(p.index + 1) % poly.length];
                Point b = poly[(p.index + poly.length - 1) % poly.length];
                if (a.x > b.x || (a.x == b.x && a.y > b.y)) {
                    Point tmp = a;
                    a = b;
                    b = tmp;
                }
                if (a.x < p.x && b.x < p.x) {
                    if ((a.x - p.x) * (long) (b.y - p.y) - (a.y - p.y) * (long) (b.x - p.x) < 0) {
                        Point tmp = a;
                        a = b;
                        b = tmp;
                    }
                    Edge bEdge = picture.floor(new Edge(b, p));
                    if (bEdge.isUpper == 2) {
                        Edge dest = picture.lower(bEdge);
                        double destY = addTransition(bEdge, dest, p.x);
                        if (prevP != null) {
                            if (prevP.y > destY) {
                                getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));
                            }
                        }
                    }
                    Edge aEdge = picture.floor(new Edge(a, p));
                    if (aEdge.isUpper == 1) {
                        Edge dest = picture.higher(aEdge);
                        addTransition(dest, aEdge, p.x);
                    }
                } else if (a.x < p.x && b.x > p.x) {
                    Edge aEdge = picture.floor(new Edge(a, p));
                    if (aEdge.isUpper == 1) {
                        Edge dest = picture.higher(aEdge);
                        addTransition(dest, aEdge, p.x);
                    } else {
                        Edge dest = picture.lower(aEdge);
                        double destY = addTransition(aEdge, dest, p.x);
                        if (prevP != null) {
                            if (prevP.y > destY) {
                                getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));
                            }
                        }
                    }
                } else if (a.x < p.x && b.x == p.x) {
                    Edge aEdge = picture.floor(new Edge(a, p));
                    if (aEdge.isUpper == 1 && b.y < p.y) {
                        Edge dest = picture.higher(aEdge);
                        addTransition(dest, aEdge, p.x);
                    } else if (aEdge.isUpper == 2 && b.y > p.y) {
                        Edge dest = picture.lower(aEdge);
                        double destY = addTransition(aEdge, dest, p.x);
                        if (prevP != null) {
                            if (prevP.y > destY) {
                                getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));
                            }
                        }
                    }
                }
                prevP = p;
            }
            for (pj = pi; pj < polyByX.length && polyByX[pj].x == polyByX[pi].x; ++pj) {
                Point p = polyByX[pj];
                Point a = poly[(p.index + 1) % poly.length];
                Point b = poly[(p.index + poly.length - 1) % poly.length];
                if (a.x < p.x) {
                    Edge toRemove = new Edge(a, p);
                    if (!picture.remove(toRemove)) throw new RuntimeException();
                }
                if (b.x < p.x) {
                    Edge toRemove = new Edge(b, p);
                    if (!picture.remove(toRemove)) {
                        throw new RuntimeException();
                    }
                }
            }
            for (pj = pi; pj < polyByX.length && polyByX[pj].x == polyByX[pi].x; ++pj) {
                Point p = polyByX[pj];
                Point a = poly[(p.index + 1) % poly.length];
                Point b = poly[(p.index + poly.length - 1) % poly.length];
                if ((a.x - p.x) * (long) (b.y - p.y) - (a.y - p.y) * (long) (b.x - p.x) < 0) {
                    Point tmp = a;
                    a = b;
                    b = tmp;
                }
                if (a.x > p.x) {
                    Edge toAdd = new Edge(a, p);
                    Edge prev = picture.lower(toAdd);
                    if (prev == null)
                        toAdd.isUpper = 1;
                    else
                        toAdd.isUpper = 3 - prev.isUpper;
                    if (!picture.add(toAdd)) throw new RuntimeException();
                }
                if (b.x > p.x) {
                    Edge toAdd = new Edge(b, p);
                    Edge prev = picture.lower(toAdd);
                    if (prev == null)
                        toAdd.isUpper = 1;
                    else
                        toAdd.isUpper = 3 - prev.isUpper;
                    if (!picture.add(toAdd)) throw new RuntimeException();
                }
            }
            prevP = null;
            for (pj = pi; pj < polyByX.length && polyByX[pj].x == polyByX[pi].x; ++pj) {
                Point p = polyByX[pj];
                Point a = poly[(p.index + 1) % poly.length];
                Point b = poly[(p.index + poly.length - 1) % poly.length];
                if (a.x > b.x || (a.x == b.x && a.y > b.y)) {
                    Point tmp = a;
                    a = b;
                    b = tmp;
                }
                if (a.x > p.x && b.x > p.x) {
                    if ((a.x - p.x) * (long) (b.y - p.y) - (a.y - p.y) * (long) (b.x - p.x) > 0) {
                        Point tmp = a;
                        a = b;
                        b = tmp;
                    }
                    Edge bEdge = picture.floor(new Edge(b, p));
                    if (bEdge.isUpper == 2) {
                        Edge dest = picture.lower(bEdge);
                        double destY = addTransition(bEdge, dest, p.x);
                        if (prevP != null) {
                            if (prevP.y > destY) {
                                getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));
                            }
                        }
                    }
                    Edge aEdge = picture.floor(new Edge(a, p));
                    if (aEdge.isUpper == 1) {
                        Edge dest = picture.higher(aEdge);
                        addTransition(dest, aEdge, p.x);
                    }
                } else if (a.x == p.x && b.x > p.x) {
                    Edge bEdge = picture.floor(new Edge(b, p));
                    if (bEdge.isUpper == 1 && a.y < p.y) {
                        Edge dest = picture.higher(bEdge);
                        addTransition(dest, bEdge, p.x);
                    } else if (bEdge.isUpper == 2 && a.y > p.y) {
                        Edge dest = picture.lower(bEdge);
                        double destY = addTransition(bEdge, dest, p.x);
                        if (prevP != null) {
                            if (prevP.y > destY) {
                                getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));
                            }
                        }
                    }
                }
                prevP = p;
            }
            pi = pj;
        }
        GraphNode start = getNodeFor(poly, s);
        GraphNode finish = getNodeFor(poly, t);
        Collections.sort(nodes);
        for (int i = 0; i + 1 < nodes.size(); ++i) {
            GraphNode n1 = nodes.get(i);
            GraphNode n2 = nodes.get(i + 1);
            if (n1.sideId == n2.sideId) {
                n1.outgo.add(n2);
                n2.outgo.add(n1);
            }
        }
        TreeSet<Reach> reaches = new TreeSet<Reach>();
        start.distance = 0;
        reaches.add(new Reach(start, 0));
        while (true) {
            Reach first = reaches.pollFirst();
            if (first.dest.mark) continue;
            first.dest.mark = true;
            if (first.dest == finish) {
                out.println(first.dest.distance / 2.0);
                return;
            }
            for (GraphNode other : first.dest.outgo) {
                double dx = first.dest.x - other.x;
                double dy = first.dest.y - other.y;
                double dd = Math.sqrt(dx * dx + dy * dy);
                double nd = first.dest.distance + dd;
                if (nd < other.distance - 1e-10) {
                    other.distance = nd;
                    reaches.add(new Reach(other, other.distance));
                }
            }
        }
	}

    private GraphNode getNodeFor(Point[] poly, int s) {
        GraphNode start;
        {
            Point sp = poly[s];
            Point spa = poly[(s + 1) % poly.length];
            Point spb = poly[(s + poly.length - 1) % poly.length];
            if (spa.x != sp.x || spa.y > sp.y) {
                start = createNode(new Edge(sp, spa), sp.x);
            } else {
                start = createNode(new Edge(sp, spb), sp.x);
            }
        }
        return start;
    }

    static class Reach implements Comparable<Reach> {
        GraphNode dest;
        double d;

        Reach(GraphNode dest, double d) {
            this.dest = dest;
            this.d = d;
        }

        public int compareTo(Reach reach) {
            if (d != reach.d) return Double.compare(d, reach.d);
            return dest.compareTo(reach.dest);
        }
    }

    private double addTransition(Edge top, Edge bottom, int x) {
        GraphNode src = createNode(top, x);
        GraphNode dst = createNode(bottom, x);
        src.outgo.add(dst);
        return dst.y;
    }

    private GraphNode createNode(Edge top, int x) {
        GraphNode src;
        {
            int i1 = top.v1.index;
            int i2 = top.v2.index;
            int i;
            if (i1 + 1 == i2 || i1 + 1 == i2 + n) {
                i = i1;
            } else if (i2 + 1 == i1 || i2 + 1 == i1 + n) {
                i = i2;
            } else {
                throw new RuntimeException();
            }
            src = new GraphNode(i, x);
            GraphNode canonicalSrc = canonical.get(src);
            if (canonicalSrc == null) {
                canonical.put(src, src);
                nodes.add(src);
                if (top.v1.x == top.v2.x)
                    src.y = Math.min(top.v1.y, top.v2.y);
                else
                    src.y = (x - top.v1.x) / (double) (top.v2.x - top.v1.x) * (top.v2.y - top.v1.y) + top.v1.y;
            } else {
                src = canonicalSrc;
            }
        }
        return src;
    }
}

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());
    }

    }


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.TreeMap;

/**
 *
 *
 *
 * @author pttrung
 */
public class D {

    public static long MOD = 1000000007;
    public static ArrayList<Integer> p;

    public static void main(String[] args) {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        long a = in.nextLong();
        long b = in.nextLong();
        long k = in.nextLong();
        boolean[] prime = new boolean[10000000];
        p = new ArrayList();
        ArrayList<Integer> list = new ArrayList();
        for (int i = 2; i < prime.length; i++) {
            if (!prime[i]) {
                p.add( i);
                if (i < k) {
                    list.add(i);
                }
                for (int j = i * i; j < prime.length; j += i) {
                    if (j < 0) {
                        break;
                    }
                    prime[j] = true;

                }
            }
        }
        boolean ok = true;
        if (k < prime.length) {
            if (prime[(int) k]) {
                out.println(0);
                ok = false;
            }
        } else {
            if (!isPrime(k)) {
                out.println(0);
                ok = false;
            }
        }
//        for(long val : p){
//            System.out.println("Prime " + val);
//        }
        // p.add(k);
        if (ok) {
            long left = cal(list.size() - 1, list, b/k);
            long right = cal(list.size() - 1, list, (a - 1)/k);
            //out.println(left + " " + right);
            out.println((left - right));
        }
        out.close();
    }

    public static boolean isPrime(long val) {
        int index = 1;
        int prime = p.get(0);
        while(prime*prime <= val && index < p.size()){
            if(val% prime == 0){
                return false;
            }
            prime = p.get(index ++);
        }
        return true;
    }

    public static long cal(int index, ArrayList<Integer> val, long n) {

        if (n == 0 || index == -1) {
            return n;
        }
        return cal(index - 1, val, n) - cal(index - 1, val, n / val.get(index));
    }

    public static class Edge implements Comparable<Edge> {

        int x, y;

        public Edge(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Edge o) {
            if (x != o.x) {
                return x - o.x;
            } else {
                return y - o.y;
            }
        }
    }

    public static class FT {

        int[] data;

        FT(int n) {
            data = new int[n];
        }

        public void update(int index, int value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public int get(int index) {
            int result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;
        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.util.Scanner;

public  final class ThreeGarlandsCF {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int k1=sc.nextInt();
        int k2=sc.nextInt();
        int k3=sc.nextInt();
        if(k1==1 || k2==1 || k3==1){
            System.out.println("YES");
        }else{
            int twoCount=0;
            int  threeCount=0;
            int fourCount=0;

            if(k1==2)
                twoCount++;
            else if(k1==3)
                threeCount++;
            else if(k1==4)
                fourCount++;

            if(k2==2)
                twoCount++;
            else if(k2==3)
                threeCount++;
            else if(k2==4)
                fourCount++;

            if(k3==2)
                twoCount++;
            else if(k3==3)
                threeCount++;
            else if(k3==4)
                fourCount++;

            if(twoCount>=2 || threeCount==3 || (twoCount==1 && fourCount==2))
                System.out.println("YES");
            else
                System.out.println("NO");
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * stescobedo
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        FNezzarAndChocolateBars solver = new FNezzarAndChocolateBars();
        solver.solve(1, in, out);
        out.close();
    }

    static class FNezzarAndChocolateBars {
        static final int MAXN = 2048;
        static final int modulo = 998244353;

        public int add(int x, int y) {
            x += y;
            if (x >= modulo) x -= modulo;
            return x;
        }

        public int subtract(int x, int y) {
            x -= y;
            if (x < 0) x += modulo;
            return x;
        }

        public int multiply(int x, int y) {
            return (int) ((x * 1L * y) % modulo);
        }

        public int power(int x, long y) {
            int ans = 1;
            for (; y > 0; y >>= 1, x = (int) ((x * 1L * x) % modulo))
                if (y % 2 == 1) ans = (int) ((ans * 1L * x) % modulo);
            return ans;
        }

        public int inverse(int x) {
            return power(x, modulo - 2);
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int[] fact = new int[MAXN];
            int[] ifact = new int[MAXN];
            fact[0] = ifact[0] = 1;
            for (int i = 1; i < MAXN; i++) {
                fact[i] = multiply(fact[i - 1], i);
                ifact[i] = inverse(fact[i]);
            }
            int n = in.nextInt(), k = in.nextInt();
            int[] l = in.readIntArray(n);
            int[][][] dp = new int[2][MAXN][n + 1];
            dp[1][0][0] = 1;
            int s = 0;

            for (int p = 0; p < n; p++) {
                int L = l[p];
                int invL = inverse(L);
                int[] coeffs = new int[L / k + 1];
                int[] coeffs2 = new int[L / k + 1];
                for (int i = 0; i <= L / k; i++) {
                    if (k * i == L) continue;
                    int z = ifact[i];
                    if (i % 2 == 1) z = subtract(0, z);
                    coeffs[i] = multiply(z, power(L - k * i, i));

                    if (i >= 1) {
                        coeffs2[i] = multiply(z, multiply(i, power(L - k * i, i - 1)));
                    }
                }
                int r = p & 1;
                int h = r ^ 1;
                for (int i = 0; i <= s / k; i++) Arrays.fill(dp[r][i], 0);
                for (int i = 0; i <= s / k; i++)
                    for (int j = 0; j <= p; j++)
                        if (dp[h][i][j] != 0) {
                            int value = dp[h][i][j];
                            for (int t = 0; t <= L / k; t++) {
                                dp[r][i + t][j] = add(dp[r][i + t][j], multiply(value, coeffs[t]));
                                if (t > 0) {
                                    dp[r][i + t - 1][j + 1] = add(dp[r][i + t - 1][j + 1], multiply(value, coeffs2[t]));
                                }
                            }
                        }
                s += L;
            }
            int answer = 0;
            for (int i = 0; i <= s / k; i++)
                for (int r = 0; r <= n; r++) {
                    int value = dp[(n - 1) & 1][i][r];
                    int j = i + r;
                    if (j == 0) continue;
                    int temp = multiply(fact[i], inverse(power(k * j, i + 1)));
                    answer = add(answer, multiply(value, temp));
                }
            out.println(multiply(subtract(0, s), answer));
        }

    }

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

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

        public int[] readIntArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++) {
                array[i] = readInt();
            }
            return array;
        }

        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 int readInt() {
            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 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);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void println(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
            writer.print('\n');
        }

        public void close() {
            writer.close();
        }

    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
    public class templ {
    int binarySearch(int arr[], int l, int r, int x)
    {
        if (r >= l)
        {
            int mid = l + (r - l)/2;
            if (arr[mid] == x)
            return mid;
            if (arr[mid] > x)
            return binarySearch(arr, l, mid-1, x);
            return binarySearch(arr, mid+1, r, x);
        }
        return -1;
    }
    int partition(int arr[], int low, int high)
    {
        int pivot = arr[high];
        int i = (low-1); // index of smaller element
        for (int j=low; j<high; j++)
        {
            if (arr[j] <= pivot)
            {
                i++;
                int temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
        int temp = arr[i+1];
        arr[i+1] = arr[high];
        arr[high] = temp;
        return i+1;
    }
    void sort(int arr[], int low, int high)
    {
        if (low < high)
        {
            int pi = partition(arr, low, high);
            sort(arr, low, pi-1);
            sort(arr, pi+1, high);
        }
    }
    public static void main(String[] args) throws FileNotFoundException {
     try
     {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        templ ob=new templ();
        int n=in.nextInt();
        int a=in.nextInt();
        int odd[]=new int[n/2];
        int even[]=new int[n/2];
        int k=0;
        for(int i=1;i<=n;i=i+2)
        {
            odd[k]=i;
            k++;
        }
        k=0;
        for(int i=n;i>=2;i-=2)
        {
            even[k]=i;
            k++;
        }
        if(a%2==0)
        {
            int x=0;
            for(int i=0;i<n/2;i++)
            {
                if(even[i]==a)
                {
                    x=i;
                    break;
                }
            }
            out.println(x+1);
        }
        else
        {
            int x=0;
            for(int i=0;i<n/2;i++)
            {
                if(odd[i]==a)
                {
                    x=i;
                    break;
                }
            }
            out.println(x+1);
        }
        out.close();
    }
        catch(Exception e){
        return;
    }
    }
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

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

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 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 {
                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 {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public String readString() {
            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 String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

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

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

    }
}


import java.util.*;
import java.lang.Math;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s =sc.next();
	    int u=0;
	    int l=0;
	    int r=0;
	    int d=0;
	    for(int i=0;i<s.length();i++){
	        if(s.charAt(i)=='U') u++;
	        if(s.charAt(i)=='L') l++;
	        if(s.charAt(i)=='D') d++;
	        if(s.charAt(i)=='R') r++;
	    }

	    System.out.println(2*Math.min(l,r) + 2*Math.min(u,d));
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGregAndFriends solver = new CGregAndFriends();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGregAndFriends {
        long mod = 1000000007;
        long INF = (long) 1e18 + 1;
        PrintWriter out;
        InputReader in;
        long[][] nCr = new long[100][100];

        long f(long p, int a, int b, int c, int d) {
            p *= nCr[a][b];
            p %= mod;
            p *= nCr[c][d];
            p %= mod;
            return p;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            int n = ni();
            int K = ni();
            int cnt1 = 0, cnt2 = 0;
            int i = 0, j = 0, k = 0;
            for (i = 0; i < 100; i++) {
                for (j = 0; j <= i; j++) {
                    if (j == 0 || j == i)
                        nCr[i][j] = 1;
                    else
                        nCr[i][j] = (nCr[i - 1][j] + nCr[i - 1][j - 1]) % mod;
                }
            }
            for (i = 0; i < n; i++) {
                if (ni() == 50)
                    cnt1++;
                else
                    cnt2++;
            }
            long[][][] dist = new long[200][200][2];
            long[][][] dp = new long[200][200][2];
            for (i = 0; i < 200; i++) {
                for (j = 0; j < 200; j++)
                    Arrays.fill(dist[i][j], INF);
            }
            dist[0][0][0] = 0;
            dp[0][0][0] = 1;
            ArrayDeque<Tuple> pq = new ArrayDeque<>();
            pq.add(new Tuple(0, 0, 0, 0));
            while (pq.size() > 0) {
                Tuple curr = pq.poll();
                int x = curr.x;
                int y = curr.y;
                int z = curr.z;
                long d = dist[x][y][z];
                if (z == 0) {
                    int rem_x = cnt1 - x;
                    int rem_y = cnt2 - y;
                    for (i = 0; i <= rem_x; i++) {
                        for (j = 0; j <= rem_y; j++) {
                            if (i + j == 0)
                                continue;
                            if (i * 50 + j * 100 > K)
                                break;
                            if (dist[i + x][j + y][z ^ 1] >= d + 1) {
                                if (dist[i + x][j + y][z ^ 1] > d + 1) {
                                    dist[i + x][j + y][z ^ 1] = d + 1;
                                    pq.add(new Tuple(dist[i + x][j + y][z ^ 1], i + x, j + y, z ^ 1));
                                    dp[i + x][j + y][z ^ 1] += f(dp[x][y][z], rem_x, i, rem_y, j);
                                    dp[i + x][j + y][z ^ 1] %= mod;
                                } else {
                                    dp[i + x][j + y][z ^ 1] += f(dp[x][y][z], rem_x, i, rem_y, j);
                                    dp[i + x][j + y][z ^ 1] %= mod;
                                }
                            }
                        }
                    }
                } else {
                    int rem_x = x;
                    int rem_y = y;
                    for (i = 0; i <= rem_x; i++) {
                        for (j = 0; j <= rem_y; j++) {
                            if (i + j == 0)
                                continue;
                            if (i * 50 + j * 100 > K)
                                break;
                            if (dist[x - i][y - j][z ^ 1] >= d + 1) {
                                if (dist[x - i][y - j][z ^ 1] > d + 1) {
                                    dist[x - i][y - j][z ^ 1] = d + 1;
                                    pq.add(new Tuple(dist[x - i][y - j][z ^ 1], x - i, y - j, z ^ 1));
                                    dp[x - i][y - j][z ^ 1] += f(dp[x][y][z], rem_x, i, rem_y, j);
                                    dp[x - i][y - j][z ^ 1] %= mod;
                                } else {
                                    dp[x - i][y - j][z ^ 1] += f(dp[x][y][z], rem_x, i, rem_y, j);
                                    dp[x - i][y - j][z ^ 1] %= mod;
                                }
                            }
                        }
                    }
                }
            }
            if (dist[cnt1][cnt2][1] == INF)
                pn(-1);
            else
                pn(dist[cnt1][cnt2][1]);
            pn(dp[cnt1][cnt2][1]);
        }

        int ni() {
            return in.nextInt();
        }

        void pn(long zx) {
            out.println(zx);
        }

        class Tuple {
            long d;
            int x;
            int y;
            int z;

            Tuple(long d, int x, int y, int z) {
                this.d = d;
                this.x = x;
                this.y = y;
                this.z = z;
            }

        }

    }

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

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

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

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

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

            return res.toString();
        }

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

    }
}


import java.io.*;
import java.util.*;
public class D9 {
	static long[][] ans;
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ans = new long[36][36];
		for(int i = 0; i < 36; i++)
			Arrays.fill(ans[i], -1);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int h = Integer.parseInt(st.nextToken());
		long ret = 0;
		for(int a = h; a <= n; a++)
			ret += solve(n,a);
		System.out.println(ret);
	}
	public static long solve(int n, int h)	{
		if(n < h || n >= (1L << h))
			return 0;
		if(n == 0 && h == 0)
			return 1;
		if(n == h){
			return 1L << (h-1);
		}
		if(ans[n][h] != -1)
			return ans[n][h];
		long ret = 0;
		for(int left = 0; left < n; left++)	{
			int right = n-1-left;
			for(int leftH = 0; leftH < h-1; leftH++)
				ret += solve(left, leftH) * solve(right, h-1);
			for(int rightH = 0; rightH < h-1; rightH++)
				ret += solve(left, h-1) * solve(right, rightH);
			ret += solve(left, h-1) * solve(right, h-1);
		}
		ans[n][h] = ret;
		return ret;
	}
}
// 27 11 should return 61162698256896
// initial returned    167110392320


import java.util.HashMap;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.List;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE_AnnAndCubics solver = new TaskE_AnnAndCubics();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE_AnnAndCubics {

    List<Long> factorials;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int k = in.nextInt();
        long S = in.nextLong();

        factorials = new ArrayList<Long>();
        factorials.add(1L);
        for (int i = 2;; ++i) {
            factorials.add(factorials.get(factorials.size()-1) * i);
            if (factorials.get(factorials.size()-1) > S) {
                break;
            }
        }
        factorials.remove(factorials.size()-1);

        int[] a = Utils.readIntArray(in, n);

        int n2 = n / 2;
        int n1 = n - n2;

        HashMap<Long, HashMap<Integer, Long>> leftSide = buildIt(n1, ArrayUtils.subArray(a, 0, n1), S, k);
        HashMap<Long, HashMap<Integer, Long>> rightSide = buildIt(n2, ArrayUtils.subArray(a, n1, n), S, k);

        long res = 0;
        for (long keyLeft : leftSide.keySet()) {
            long needKey = S - keyLeft;
            if (needKey >= 0 && rightSide.containsKey(needKey)) {
                res += getIt(leftSide.get(keyLeft), rightSide.get(needKey), k);
            }
        }
        out.println(res);
    }

    private long getIt(HashMap<Integer, Long> left, HashMap<Integer, Long> right, int k) {
        long res = 0;
        for (int key : left.keySet()) {
            for (int key2 : right.keySet()) {
                if (key + key2 <= k) {
                    res += left.get(key) * right.get(key2);
                }
            }
        }
        return res;
    }

    private HashMap<Long, HashMap<Integer, Long>> buildIt(int n, int[] a, long S, int k) {
        HashMap<Long, HashMap<Integer, Long>> res = new HashMap<Long, HashMap<Integer, Long>>();

        for (int set = 0; set < (1 << n); ++set) {
            for (int subset = set; subset >= 0; subset = ((subset - 1) & set)) {
                if (Integer.bitCount(subset) > k) continue;
                long sum = 0;
                boolean badMask = false;
                for (int i = 0; i < n; ++i) {
                    if (BitUtils.checkBit(subset, i)) {
                        if (a[i] > factorials.size()) {
                            badMask = true;
                            break;
                        } else {
                            sum += factorials.get(a[i] - 1);
                        }
                    } else if (BitUtils.checkBit(set, i)) {
                        sum += a[i];
                    }
                    if (sum > S) {
                        badMask = true;
                        break;
                    }
                }
                if (!badMask) {
                    if (sum <= S) {
                        addToRes(res, Integer.bitCount(subset), sum);
                    }
                }
                if (subset == 0) break;
            }
        }
        return res;
    }

    private void addToRes(HashMap<Long, HashMap<Integer, Long>> dict, int k, long sum) {
        if (!dict.containsKey(sum)) {
            HashMap<Integer, Long> map = new HashMap<Integer, Long>();
            map.put(k, 1L);
            dict.put(sum, map);
        } else {
            HashMap<Integer, Long> map = dict.get(sum);
            if (!map.containsKey(k)) {
                map.put(k, 1L);
            } else {
                map.put(k, map.get(k) + 1);
            }
            dict.put(sum, map);
        }
    }

}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

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

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

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

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

}

class Utils {
    public static int[] readIntArray(InputReader in, int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }
        return a;
    }

}

class ArrayUtils {

    public static int[] subArray(int[] a, int start, int finish) {
        int[] result = new int[finish - start];
        for (int i = start; i < finish; ++i) {
            result[i-start] = a[i];
        }
        return result;
    }

}

class BitUtils {
    public static boolean checkBit(int mask, int bit) {
        return (mask & (1 << bit)) > 0;
    }

}


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

public class MadokaAndTheBestUniversity {
	private static final int N_MAX = 100_000;

	private static final int MOD = 1_000_000_007;

	private static final IntList[] FACTORS = new IntList[N_MAX + 1];
	static {
		for (int i = 1; i <= N_MAX; ++i) {
			FACTORS[i] = new IntList();
		}
		for (int i = 1; i <= N_MAX; ++i) {
			for (int j = i; j <= N_MAX; j += i) {
				FACTORS[j].add(i);
			}
		}
	}

	private static final int[] TOTIENT = new int[N_MAX + 1];
	static {
		for (int i = 1; i < TOTIENT.length; ++i) {
			TOTIENT[i] = i;
		}
		for (int i = 2; i < TOTIENT.length; ++i) {
			if (TOTIENT[i] != i) {
				continue;
			}
			for (int j = i; j < TOTIENT.length; j += i) {
				TOTIENT[j] -= TOTIENT[j] / i;
			}
		}
	}

	public static void solve(FastIO io) {
		final int N = io.nextInt();

		long total = 0;
		for (int c = 1; c + 2 <= N; ++c) {
			int rem = N - c;
			IntList facs = FACTORS[rem];
			for (int i = facs.size() - 2; i >= 0; --i) {
				int fi = facs.get(i);
				total += 1L * lcm(c, fi) * TOTIENT[rem / fi];
				total %= MOD;
			}
		}
		io.println(total);
	}

	/**
	 * Computes the GCD (greatest common denominator) between two numbers.
	 */
	public static int gcd(int a, int b) {
		if (a < b)
			return gcd(b, a);

		int r = a % b;
		if (r == 0)
			return b;

		return gcd(b, r);
	}

	/**
	 * Computes the LCM (least common multiple) between all the numbers.
	 */
	public static int lcm(int... arr) {
		int lcm = arr[0];
		for (int i = 1; i < arr.length; i++)
			lcm = lcm * arr[i] / gcd(lcm, arr[i]);

		return lcm;
	}

	private static class IntList extends ArrayList<Integer> {
		private static final long serialVersionUID = 8986468115134862220L;
	}

	public static class FastIO {
		private InputStream reader;
		private PrintWriter writer;

		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastIO(InputStream r, OutputStream w) {
			reader = r;
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
		}

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

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

		public String nextString() {
			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 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 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;
		}

		// TODO: read this byte-by-byte like the other read functions.
		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			return nextIntArray(n, 0);
		}

		public int[] nextIntArray(int n, int off) {
			int[] arr = new int[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			return nextLongArray(n, 0);
		}

		public long[] nextLongArray(int n, int off) {
			long[] arr = new long[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextLong();
			}
			return arr;
		}

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

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

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

		public void printArray(int[] arr) {
			for (int i = 0; i < arr.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(arr[i]);
			}
		}

		public void printArray(long[] arr) {
			for (int i = 0; i < arr.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(arr[i]);
			}
		}

		public void printlnArray(int[] arr) {
			printArray(arr);
			writer.println();
		}

		public void printlnArray(long[] arr) {
			printArray(arr);
			writer.println();
		}

		public void printf(String format, Object... args) {
			print(String.format(format, args));
		}

		public void flush() {
			writer.flush();
		}
	}

	public static void main(String[] args) {
		FastIO io = new FastIO(System.in, System.out);
		solve(io);
		io.flush();
	}
}


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

public class E {

    static int N, M, K;
    static String s;
    static StringTokenizer st;
    static int[] d;
    static long[] fact;

    static HashSet<Integer> hm = new HashSet();
    static long c(int[] d) {
        //System.out.println(Arrays.toString(d));
        int l = Arrays.hashCode(d);
        if(hm.contains(l)){
            return 0;
        }
        long top = 0;
        long bot = 1;
        int sum = 0;
        for (int i = 0; i < d.length; i++) {
            sum += d[i];
            bot *= fact[d[i]];
        }
        //System.out.println(sum);
        long ans = fact[sum];
        for (int i = 0; i < d.length; i++) {
            ans /= fact[d[i]];
        }
        //long ans = top / bot;
        //System.out.println(top + " " + bot);
        //System.out.println(ans);

        long ans2 = 0;
        if (d[0] > 0) {;
            ans2 = fact[sum-1];
            d[0]--;
            for (int i = 0; i < d.length; i++) {
                ans2 /= fact[d[i]];
            }
            d[0]++;
        }

        hm.add(l);

        //System.out.println(Arrays.toString(d) + " " + sum + " " + ans + " " + ans2);
        return ans-ans2;
    }

    public static long DFS(int[] d) {
        //System.out.println(Arrays.toString(d));
        long ans = c(d);
        //System.out.println(ans);
        for (int i = 0; i < d.length; i++) {
            if (d[i] > 1) {
                int[] d2 = new int[d.length];
                for (int j = 0; j < d.length; j++) {
                    d2[j] = d[j];
                }
                d2[i]--;
                ans += DFS(d2);
            }
        }
        //System.out.println("returning " + ans);
        if (ans < 0) {
            while (true) {

            }
        }

        return ans;
    }

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        fact = new long[20];
        fact[0] = 1;

        for (int i = 1; i < 20; i++) {
            fact[i] = fact[i - 1] * i;
        }

        //System.out.println(Arrays.toString(fact));
        //System.out.println(fact[18]);
        int[] d = new int[10];
        long N = Long.parseLong(br.readLine());
        while (N > 0) {
            d[(int) (N % 10)]++;
            N /= 10;
        }

        long ans = DFS(d);
        System.out.println(ans);
        //System.out.println(fact[19]);
        //System.out.println(c(d));

        out.close();
    }
}


import java.util.*;

public class CodeForces {
	Scanner scan = new Scanner(System.in);

	private static long gcd(long a, long b)
	{
	    while (b > 0)
	    {
	        long temp = b;
	        b = a % b;
	        a = temp;
	    }
	    return a;
	}

	private static long gcd(long[] input)
	{
	    long result = input[0];
	    for(int i = 1; i < input.length; i++) result = gcd(result, input[i]);
	    return result;
	}

	private static long lcm(long a, long b)
	{
	    return a * (b / gcd(a, b));
	}

	private static long lcm(long[] input)
	{
	    long result = input[0];
	    for(int i = 1; i < input.length; i++) result = lcm(result, input[i]);
	    return result;
	}

	CodeForces()
	{
	String s,x,y,a,b;
	s = scan.nextLine();
	String [] temp = s.split(" ");
	x = temp[0];
	y = temp[1];
	a = temp[2];
	b = temp[3];
	boolean flag = false;
	long[] input = new long[2];
	input[0] = Integer.parseInt(x);
	input[1] = Integer.parseInt(y);
	long kpk = lcm(input);
	long counter = 0;
	long start = 0;
	for(long i=Integer.parseInt(a);i<=Integer.parseInt(b)&&!flag;i++)
	{
		if(i%Integer.parseInt(y)==0&&i%Integer.parseInt(x)==0)
		{
			++counter;
			flag = true;
			start = i;
		}
	}
	long remain = flag?(Integer.parseInt(b) - start) / kpk:0;
	counter+=remain;
	System.out.println(counter);
	}
	public static void main(String[] args)
	{
	new CodeForces();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.util.TreeMap;
public class E1113
{
    static class QN{
        int index;
        long sum;
        QN(int in,long an){
            index=in;
            sum=an;
        }
    }
    static class SegmentTree{
        long sum,pmin,lazy;
        int st,en;
        boolean rem;
        SegmentTree left,right;
        SegmentTree(int _st,int _en,long _v){
            st=_st;
            en=_en;
            lazy=_v;
            rem=true;
            sum=(en-st+1)*lazy;
            pmin=Math.min(lazy,sum);
        }
        long pmin(){
            return rem?(Math.min(lazy,(en-st+1)*lazy)):(pmin);
        }
        long sum(){
            return rem?((en-st+1)*lazy):(sum);
        }
        void update(int l,int r,long v){
            //completely outside
            if(l>en||r<st)
                return;
            //completely inside
            if(l<=st&&r>=en){
                //update lazy;
                lazy=v;
                rem=true;
                return;
            }
            //partial cover
            lazyPropagate();
            left.update(l, r, v);
            right.update(l, r, v);
            sum=left.sum()+right.sum();
            pmin=Math.min(left.pmin(),left.sum()+right.pmin());
            return;
        }
        void lazyPropagate(){
            if(left==null){
                int mid=(st+en)>>1;
                left=new SegmentTree(st,mid,lazy);
                right=new SegmentTree(mid+1,en,lazy);
            }else if(rem){
                left.lazy=lazy;
                right.lazy=lazy;
                left.rem=true;
                right.rem=true;
            }
            if(rem){
                sum=(en-st+1)*lazy;
                pmin=Math.min(lazy,sum);
            }
            rem=false;
        }
        /**returns least index which has value <= given value**/
        QN query(int l,int r,long v,long su){
            //no cover
            if(st>r||en<l)
                return new QN(-1,0);
            //full cover
            if(l<=st&&en<=r){
                if(su+pmin()<=v)
                    return query2(v,su);
                return new QN(-1,su+sum());
            }
            lazyPropagate();

            QN q1=left.query(l,r,v,su);
            if(q1.index!=-1)
                return q1;
            q1=right.query(l,r,v,q1.sum);
            return q1;
        }
        QN query2(long v,long su){
            if(st==en)
                return new QN(st,su+sum());
            lazyPropagate();
            if(left.pmin()+su<=v)
                return left.query2(v,su);
            else
                return right.query2(v,su+left.sum());

        }

    }
    static class Scanner
    {
        BufferedReader br;
        StringTokenizer tk=new StringTokenizer("");
        public Scanner(InputStream is)
        {
            br=new BufferedReader(new InputStreamReader(is));
        }
        public int nextInt() throws IOException
        {
            if(tk.hasMoreTokens())
                return Integer.parseInt(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextInt();
        }
        public long nextLong() throws IOException
        {
            if(tk.hasMoreTokens())
                return Long.parseLong(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextLong();
        }
        public String next() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return next();
        }
        public String nextLine() throws IOException
        {
            tk=new StringTokenizer("");
            return br.readLine();
        }
        public double nextDouble() throws IOException
        {
            if(tk.hasMoreTokens())
                return Double.parseDouble(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextDouble();
        }
        public char nextChar() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken().charAt(0));
            tk=new StringTokenizer(br.readLine());
            return nextChar();
        }
        public int[] nextIntArray(int n) throws IOException
        {
            int a[]=new int[n];
            for(int i=0;i<n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArray(int n) throws IOException
        {
            long a[]=new long[n];
            for(int i=0;i<n;i++)
                a[i]=nextLong();
            return a;
        }
        public int[] nextIntArrayOneBased(int n) throws IOException
        {
            int a[]=new int[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArrayOneBased(int n) throws IOException
        {
            long a[]=new long[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextLong();
            return a;
        }

    }

    public static void main(String args[]) throws IOException
    {
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        SegmentTree st=new SegmentTree(1,1000000000,0);
        int q=in.nextInt();
        TreeMap<Integer,Integer> mp=new TreeMap<>();
        mp.put(0,0);
        mp.put(1000000001,0);
        while(q--!=0){
            int tp=in.nextInt();
            switch(tp){
                case 1:
                    int tm=in.nextInt();
                    int vl=in.nextInt();
                    int nxt=mp.higherKey(tm)-1;
                    st.update(tm, nxt, vl);
                    mp.put(tm,vl);
                    break;
                case 2:
                    int tc=in.nextInt();
                    int vp=mp.lowerEntry(tc).getValue();
                    int net=mp.higherKey(tc)-1;
                    st.update(tc, net, vp);
                    mp.remove(tc);
                    break;
                case 3:
                    int l=in.nextInt();
                    int lc=l;
                    l=mp.ceilingKey(l);
                    int r=in.nextInt();
                    int v=in.nextInt();
                    if(v==0){
                        out.println(lc);
                        continue;
                    }
                    if(l>=r){
                        out.println(-1);
                        continue;
                    }
                    QN aa=st.query(l, r-1, -v, 0);
                    if(aa.index==-1)
                        out.println(-1);
                    else{
                        int spd=mp.floorEntry(aa.index).getValue();
                        double remv=-(v+(aa.sum-spd));
                        double anss=aa.index;
                        anss+=remv/spd;
                        out.println(anss);

                    }

            }

        }
        out.close();
    }

}


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

public class Ada extends PrintWriter {
    Ada() { super(System.out, true); }
    Scanner sc = new Scanner(System.in);
    public static void main(String[] $) {
        Ada o = new Ada(); o.main(); o.flush();
    }

    int compress(int[] aa, int n) {
        Random rand = new Random();
        for (int i = 0; i < n; i++) {
            int j = rand.nextInt(i + 1);
            int tmp = aa[i]; aa[i] = aa[j]; aa[j] = tmp;
        }
        Arrays.sort(aa, 0, n);
        int m = 1;
        for (int i = 1; i < n; i++)
            if (aa[i] != aa[i - 1])
                aa[m++] = aa[i];
        return m;
    }
    void main() {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int n = a + b;
        int s = (int) Math.sqrt(n) + 1;
        int[] gg = new int[s + s];
        int m = 0;
        for (int g = 1; g <= s; g++)
            gg[m++] = g;
        for (int k = 1; k <= s; k++) {
            int g = n / k;
            gg[m++] = g;
        }
        m = compress(gg, m);
        int ans = 0;
        for (int h = 0; h < m; h++) {
            int g = gg[h];
            int al = (int) ((a + (long) g) / (g + 1));
            int bl = (int) ((b + (long) g) / (g + 1));
            int ar = a / g;
            int br = b / g;
            if (al <= ar && bl <= br) {
                int l = Math.max(n / (g + 1) + 1, al + bl);
                int r = Math.min(n / g, ar + br);
                if (l <= r)
                    ans += r - l + 1;
            }
        }
        println(ans);
    }
}