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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author emotionalBlind
 */
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);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    int[] lo;
    int[] hi;

    long[][][][][] dp;
    long[] posVal;

    long go(int pos, int isAGreaterLo, int isALessHi, int isBGreaterLo, int isBLessHi) {
        if (pos == 63) {
            return 0;
        }
        if (dp[pos][isAGreaterLo][isALessHi][isBGreaterLo][isBLessHi] != -1) {
            return dp[pos][isAGreaterLo][isALessHi][isBGreaterLo][isBLessHi];
        }
        // range a
        int ua = 0;
        int va = 1;
        if (isALessHi == 0 && hi[pos] == 0) {
            va = 0;
        }
        if (isAGreaterLo == 0 && lo[pos] == 1) {
            ua = 1;
        }
        // range b;
        int ub = 0;
        int vb = 1;
        if (isBLessHi == 0 && hi[pos] == 0) {
            vb = 0;
        }
        if (isBGreaterLo == 0 && lo[pos] == 1) {
            ub = 1;
        }
        long res = 0;
        dp[pos][isAGreaterLo][isALessHi][isBGreaterLo][isBLessHi] = 0;
        for (int i = ua; i <= va; ++i) {
            int newIsAGreaterLo = isAGreaterLo;
            int newIsALessHi = isALessHi;
            if (i < hi[pos]) newIsALessHi = 1;
            if (i > lo[pos]) newIsAGreaterLo = 1;
            for (int j = ub; j <= vb; ++j) {
                int newIsBGreaterLo = isBGreaterLo;
                int newIsBLessHi = isBLessHi;
                if (j < hi[pos]) newIsBLessHi = 1;
                if (j > lo[pos]) newIsBGreaterLo = 1;
                long val = 0;
                if (i != j) val = posVal[pos];
                val += go(pos + 1, newIsAGreaterLo, newIsALessHi, newIsBGreaterLo, newIsBLessHi);
                res = Math.max(res, val);
            }
        }
        dp[pos][isAGreaterLo][isALessHi][isBGreaterLo][isBLessHi] = res;
        return res;
    }

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        lo = new int[63];
        hi = new int[63];
        long a = in.readLong();
        long b = in.readLong();
        Binary.convertBinary(a, lo);
        Binary.convertBinary(b, hi);
        posVal = new long[63];
        posVal[62] = 1;
        for (int i = 61; i >= 0; --i) {
            posVal[i] = posVal[i + 1] * 2;
        }
        dp = new long[65][2][2][2][2];
        for (long[][][][] a1 : dp) {
            for (long[][][] a2 : a1) {
                for (long[][] a3 : a2) {
                    for (long[] a4 : a3) {
                        Arrays.fill(a4, -1);
                    }
                }
            }
        }
        long res = go(0, 0, 0, 0, 0);
        out.printLine(res);
    }
}

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() {
        // InputMismatchException -> UnknownError
        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 long readLong() {
        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 static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }

class OutputWriter {
    private final PrintWriter writer;

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

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

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

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

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

}

class Binary {
    public static void convertBinary(long val, int[] a) {
        int last = a.length - 1;
        Arrays.fill(a, 0);
        while (val > 0) {
            a[last] = (int) (val % 2);
            last--;
            val /= 2;
        }
    }
}


import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author Abhimanyu Singh
 *
 */
public class LittleGirlAndMaximumXOR {

    private InputStream input;
    private PrintStream output;
    private Scanner inputSc;
    static final boolean ONE = true;
    static final boolean ZERO = false;
    char dp[][][];

    public LittleGirlAndMaximumXOR(InputStream input, PrintStream output) {
        this.input = input;
        this.output = output;
        init();
    }

    private void init() {
        inputSc = new Scanner(input);
    }

    static int lineToInt(String line) {
        return Integer.parseInt(line);
    }

    public void solve() {
        solveTestCase(1);
    }

    void fill(char a[], long value) {
        String str = Long.toBinaryString(value);
        char array[] = str.toCharArray();
        int len = array.length;
        int index = 63;
        while (len > 0) {
            a[index] = array[len - 1];
            len--;
            index--;
        }
    }

    void init(char a[]) {
        for (int i = 0; i < 64; i++) {
            a[i] = '0';
        }
    }

    /*
     char[] getMax0(char lBit[], char rBit[], int lIndex, int rIndex) {
     char ans[]=new char[64];
     if(lIndex)
     }

     char[] getMax(char lBit[], char rBit[], int lIndex, int rIndex) {
     }*/
    private void solveTestCase(int testN) {
        long l = inputSc.nextLong();
        long r = inputSc.nextLong();
        char lBit[] = new char[64];
        char rBit[] = new char[64];
        init(lBit);
        init(rBit);
        fill(lBit, l);
        fill(rBit, r);
        int i = 0;
        char ansBit[] = new char[64];
        char a[] = new char[64];
        char b[] = new char[64];
        init(a);
        init(b);
        init(ansBit);
        for (; i < 64; i++) {
            if (lBit[i] == '0' && rBit[i] == '0') {
            } else if (lBit[i] == '1' && rBit[i] == '0') {
                throw new RuntimeException("Wrong Input");
            } else if (lBit[i] == '0' && rBit[i] == '1') {
                a[i] = '0';
                b[i] = '1';
                break;
            } else {
                a[i] = '1';
                b[i] = '1';
            }
        }
        boolean aLessB = true;
        boolean aBig = false;
        boolean bSmall = false;
        for (; i < 64; i++) {
            if (lBit[i] == '0' && rBit[i] == '0') {
                a[i] = '1';
                b[i] = '0';
                aBig = true;
            } else if (lBit[i] == '1' && rBit[i] == '0') {
                a[i] = '1';
                b[i] = '0';
            } else if (lBit[i] == '0' && rBit[i] == '1') {
                a[i] = '0';
                b[i] = '1';
            } else {
                a[i] = '1';
                b[i] = '0';
                bSmall = true;
            }
        }
        for (i = 0; i < 64; i++) {
            if (a[i] == '0' && b[i] == '0') {
                ansBit[i] = '0';
            } else if (a[i] == '1' && b[i] == '0') {
                ansBit[i] = '1';
            } else if (a[i] == '0' && b[i] == '1') {
                ansBit[i] = '1';
            } else {
                ansBit[i] = '0';
            }
        }
        String ansStr = new String(ansBit);
        long ansValue = Long.parseLong(ansStr, 2);
        output.println(ansValue);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        LittleGirlAndMaximumXOR lgamx = new LittleGirlAndMaximumXOR(System.in, System.out);
        lgamx.solve();
    }
}


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

public class Main {
    static BufferedReader f;
    static StringTokenizer st;
    public static void main (String [] args) throws Exception {

        // Use BufferedReader rather than RandomAccessFile; it's much faster
        f = new BufferedReader(new java.io.InputStreamReader(System.in));

        long unixTime = System.currentTimeMillis();

        long l=nextLong();
        long r=nextLong();

        String ll=Long.toBinaryString(l);
        String rr=Long.toBinaryString(r);

        System.err.println(ll);
        System.err.println(rr);

        System.err.println(Long.parseLong(rr,2));

        int len=0;
        if(ll.length()!=rr.length()){
            len=Math.max(ll.length(),rr.length());
        }else{
            //same
            for(int i=0;i<ll.length();i++){
                if(ll.charAt(i)!=rr.charAt(i)){
                    len=ll.length()-i;
                    break;
                }
            }
        }
        System.err.println(len);
        //long out=0;
        StringBuffer s=new StringBuffer();
        for(int i=0;i<len;i++){
            //out+=Math.pow(2, i);
            s.append(1);
        }

        if(len==0){
            System.out.println(0);
        }else{
            System.out.println(Long.parseLong(s.toString(),2));
        }

//      System.out.println("Time elapsed (ms): "+(System.currentTimeMillis()-unixTime));

        System.exit(0);                               // don't omit this!
      }

    //Library

    static long nextLong() throws Exception{
        return Long.parseLong(next());
    }
    static int nextInt() throws Exception {
         return Integer.parseInt(next());
     }

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

}
class ii{
    int a;
    int b;
    public ii(int a, int b){
        this.a=a;
        this.b=b;
    }
}


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

public class D {

	final int MOD = (int)1e9 + 7;
	final double eps = 1e-12;
	final int INF = (int)1e9;

	public D () {
		long L = sc.nextLong();
		long R = sc.nextLong();

		int Z = 64 - Long.numberOfLeadingZeros(L ^ R);
		long res = (1L << Z) - 1;
		exit(res);
	}

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

	/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */

	static MyScanner sc = new MyScanner();

	static class MyScanner {
		public String next() {
			newLine();
			return line[index++];
		}

		public char nextChar() {
			return next().charAt(0);
		}

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

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

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

		public String nextLine() {
			line = null;
			return readLine();
		}

		public String [] nextStrings() {
			line = null;
			return readLine().split(" ");
		}

		public char [] nextChars() {
			return next().toCharArray();
		}

		public Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}

		public Long [] nextLongs() {
			String [] L = nextStrings();
			Long [] res = new Long [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Long.parseLong(L[i]);
			return res;
		}

		public Double [] nextDoubles() {
			String [] L = nextStrings();
			Double [] res = new Double [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Double.parseDouble(L[i]);
			return res;
		}

		public String [] next (int N) {
			String [] res = new String [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.next();
			return res;
		}

		public Integer [] nextInt (int N) {
			Integer [] res = new Integer [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextInt();
			return res;
		}

		public Long [] nextLong (int N) {
			Long [] res = new Long [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextLong();
			return res;
		}

		public Double [] nextDouble (int N) {
			Double [] res = new Double [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextDouble();
			return res;
		}

		public String [][] nextStrings (int N) {
			String [][] res = new String [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextStrings();
			return res;
		}

		public Integer [][] nextInts (int N) {
			Integer [][] res = new Integer [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextInts();
			return res;
		}

		public Long [][] nextLongs (int N) {
			Long [][] res = new Long [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextLongs();
			return res;
		}

		public Double [][] nextDoubles (int N) {
			Double [][] res = new Double [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextDoubles();
			return res;
		}

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

		private boolean eol() {
			return index == line.length;
		}

		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private final BufferedReader r;

		MyScanner () {
			this(new BufferedReader(new InputStreamReader(System.in)));
		}

		MyScanner(BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}

		private String [] line;
		private int index;

		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}

	static void print(Object o, Object... a) {
		printDelim(" ", o, a);
	}

	static void cprint(Object o, Object... a) {
		printDelim("", o, a);
	}

	static void printDelim (String delim, Object o, Object... a) {
		pw.println(build(delim, o, a));
	}

	static void exit (Object o, Object... a) {
		print(o, a);
		exit();
	}

	static void exit () {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}

	void NO() {
		throw new Error("NO!");
	}

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

	static String build(String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.toString().trim();
	}

	static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>) {
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		} else
			b.append(delim).append(o);
	}

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

	public static void main(String[] args) {
		new D();
		exit();
	}

	static void start() {
		t = millis();
	}

	static PrintWriter pw = new PrintWriter(System.out);

	static long t;

	static long millis() {
		return System.currentTimeMillis();
	}
}


import java.util.*;

public class D {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long L = sc.nextLong();
		long R = sc.nextLong();
		long res = Math.max(2 * Long.highestOneBit(L ^ R) - 1, 0);
		System.out.println(res);
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.Random;
import java.util.StringTokenizer;

/**
 * @author Polyarniy Nickolay
 */
public class ProblemD {

    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer tok;
    private final String DELIMETER = " ";
    private final boolean ENABLE_MULTITEST = false;
    private final boolean DEBUG = true;
    private final String FILENAME = null;//if FILENAME = null, then works with console

    public void run() throws Exception {
        initInputOutput();
        do {
            init();
            solve();
        } while (hasMoreTokens() && ENABLE_MULTITEST);
        finish();
    }

    private void init() throws Exception {
    }

    private void solve() throws Exception {
        String a = Long.toBinaryString(nextLong());
        String b = Long.toBinaryString(nextLong());
        while (a.length() < 64) {
            a = "0" + a;
        }
        while (b.length() < 64) {
            b = "0" + b;
        }
//        out.println(a);
//        out.println(b);
        char[] res = new char[a.length()];
        int cur = 0;
        while (cur < a.length() && a.charAt(cur) == b.charAt(cur)) {
            res[cur] = '0';
            cur++;
        }
        while (cur < res.length) {
            res[cur] = '1';
            cur++;
        }

        out.println(Long.valueOf(new String(res), 2));
    }

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

    private void initInputOutput() throws Exception {
        if (FILENAME == null) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    private void shuffleArray(Object[] arr) {
        Random r = new Random();
        for (int i = 0; i < arr.length; ++i) {
            Object tmp = arr[i];
            int j = r.nextInt(arr.length);
            arr[i] = arr[j];
            arr[j] = tmp;
        }
    }

    private void shuffleArray(int[] arr) {
        Random r = new Random();
        for (int i = 0; i < arr.length; ++i) {
            int tmp = arr[i];
            int j = r.nextInt(arr.length);
            arr[i] = arr[j];
            arr[j] = tmp;
        }
    }

    private int[] nextArrayInt(int n) throws Exception {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = nextInt();
        }
        return res;
    }

    private String nextWord() throws Exception {
        if (updateTokenizer()) {
            return null;
        } else {
            return tok.nextToken();
        }
    }

    private boolean hasMoreTokens() throws Exception {
        return !updateTokenizer();
    }

    private boolean updateTokenizer() throws Exception {
        while (tok == null || !tok.hasMoreTokens()) {
            String nextLine = in.readLine();
            if (nextLine == null || nextLine.isEmpty()) {
                return true;
            }
            tok = new StringTokenizer(nextLine, DELIMETER);
        }
        return false;
    }

    private int nextInt() throws Exception {
        return Integer.parseInt(nextWord());
    }

    private long nextLong() throws Exception {
        return Long.parseLong(nextWord());
    }

    private void finish() throws Exception {
        in.close();
        out.close();
    }

    private void print(String s) {
        if (DEBUG) {
            System.out.print(s);
        }
    }

    private void println(String s) {
        if (DEBUG) {
            System.out.println(s);
        }
    }

    private void println() {
        if (DEBUG) {
            System.out.println();
        }
    }

    private long[] getFirstSimpleNums(int n) {
        boolean[] notPr = new boolean[n];
        int res = n;
        notPr[0] = true;
        res--;
        notPr[1] = true;
        res--;
        for (int i = 2; i < n; ++i) {
            if (!notPr[i]) {
                for (int j = i + i; j < n; j += i) {
                    if (!notPr[j]) {
                        notPr[j] = true;
                        res--;
                    }
                }
            }
        }
        long[] resA = new long[res];
        int next = 0;
        for (int i = 0; i < n; i++) {
            if (!notPr[i]) {
                resA[next] = i;
                next++;
            }
        }
        return resA;
    }

    private static class Pair {

        int a;
        int b;

        public Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }
        public static final Comparator<Pair> comparator = new Comparator<Pair>() {

            @Override
            public int compare(Pair pair1, Pair pair2) {
                return (pair1.a - pair2.a) != 0 ? (pair1.a - pair2.a) : (pair1.b - pair2.b);
            }
        };

        @Override
        public String toString() {
            return "{" + a + "|" + b + '}';
        }
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class D {

	static StringTokenizer st;
	static BufferedReader in;
	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		long L = nextLong();
		long R = nextLong();
		if (L==R) {
			System.out.println(0);
			return;
		}
		String s1 = Long.toBinaryString(L), s2 = Long.toBinaryString(R);
		while (s1.length() != s2.length())
			s1 = "0"+s1;
		for (int i = 0; i < s1.length(); i++) {
			if (s1.charAt(i) != s2.charAt(i)) {
				int pow = s1.length()-i;
				System.out.println((long)Math.pow(2, pow)-1);
				return;
			}
		}
		pw.close();
	}
	private static int nextInt() throws IOException{
		return Integer.parseInt(next());
	}

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

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

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


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

public class con169_D {

	private static final boolean DEBUG = false;

	public static void main( final String[] args ) throws Exception {
		final BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
		final String line = br.readLine();
		final StringTokenizer tok = new StringTokenizer( line );

		final long L = Long.parseLong( tok.nextToken() );
		final long R = Long.parseLong( tok.nextToken() );

		System.out.println( solve( L, R ) );
	}

	public static long solve( final long L, final long R ) {
		if ( L == R ) return L ^ R;
		if ( DEBUG ) System.out.printf( "L=%d (%s), R=%d (%s)\n", L, Long.toBinaryString( L ), R,
				Long.toBinaryString( R ) );

		final int ld = length( L );
		final int ldm1 = ld - 1;
		final int rd = length( R );

		if ( ld < rd ) {
			long max = 1;
			while ( length( max ) < rd ) {
				max <<= 1;
			}
			long min = 1;
			while ( length( min ) < rd - 1 ) {
				min <<= 1;
				++min;
			}
			if ( DEBUG ) System.out.printf( "min=%d (%s), max=%d (%s)\n", min, Long.toBinaryString( min ), max,
						Long.toBinaryString( max ) );
			return min ^ max;
		} else {
			final char[] minStr = Long.toBinaryString( L ).toCharArray();
			final char[] maxStr = Long.toBinaryString( R ).toCharArray();
			final char[] res = new char[minStr.length];
			Arrays.fill( res, '0' );
			{
				int i = 0;
				while ( i < res.length ) {
					if ( minStr[ i ] == maxStr[ i ] ) {
						res[ i ] = '0';
					} else {
						break;
					}
					++i;
				}
				if ( DEBUG ) System.out.println( "diff at pos: " + i );
				if ( minStr[ i ] == '0' ) {
					res[ i++ ] = '1';
					for ( int j = i; j < res.length; ++j ) {
						res[ j ] = '1';
					}
				} else {
					throw new IllegalArgumentException();
				}
			}
			return Long.parseLong( new String( res ), 2 );
		}
	}

	private static int length( long l ) {
		int res = 0;
		while ( l > 0 ) {
			++res;
			l >>= 1;
		}
		return res;
	}

}


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

public class Codeforces
{
  public StreamTokenizer st;
  public PrintWriter pw;
  public static final int modulo = 1000000009;

  static class Point
  {
    public int x, y;
    Point(int _x, int _y)
    {
      x = _x;
      y = _y;
    }
  }

  void init(String in, String out)
  {
    if (in.isEmpty())
      st = new StreamTokenizer(System.in);
    else
    {
      try
      {
        st = new StreamTokenizer(new BufferedReader(new FileReader(in)));
      }
      catch(FileNotFoundException e)
      {

      }
    }

    if (out.isEmpty())
      pw = new PrintWriter(System.out);
    else
    {
      try
      {
        pw = new PrintWriter(new FileWriter(out));
      }
      catch(IOException e)
      {

      }
    }
  }

  private void close()
  {
    pw.close();
  }

  private int nI()
  {
    try{
      st.nextToken();
    }
    catch(IOException e)
    {

    }
    return (int)st.nval;
  }

  private double nD()
  {
    try{
      st.nextToken();
    }
    catch(IOException e)
    {

    }
    return st.nval;
  }

  private String nS()
  {
    try{
      st.nextToken();
    }
    catch(IOException e)
    {

    }
    return st.sval;
  }

  private long nL()
  {
    try{
      st.nextToken();
    }
    catch(IOException e)
    {

    }
    return (long)st.nval;
  }

  public static void qSort(int[] A, int low, int high) {
    int i = low;
    int j = high;
    int x = A[(low+high)/2];
    do {
        while(A[i] < x) ++i;
        while(A[j] > x) --j;
        if(i <= j){

            int temp = A[i];
            A[i] = A[j];
            A[j] = temp;

            i++; j--;
        }
    } while(i < j);
    if(low < j)
      qSort(A, low, j);
    if(i < high)
      qSort(A, i, high);

}

  public static void main(String[] aslkdjlkgja) throws IOException
  {
    Codeforces z = new Codeforces();
    z.init("", "");

    long l = z.nL();
    long r = z.nL();
    if ( l == r)
    {
      System.out.println(0);
      z.close();
      return;
    }

    List<Boolean> R = new ArrayList<Boolean>();
    List<Boolean> L = new ArrayList<Boolean>();

    long temp = r;
    while (temp != 0)
    {
      if (temp % 2 == 1)
        R.add(true);
      else
        R.add(false);
      temp /= 2;
    }

    Collections.reverse(R);

    temp = l;
    while (temp != 0)
    {
      if (temp % 2 == 1)
        L.add(true);
      else
        L.add(false);
      temp /= 2;
    }

    int n = R.size() - L.size();
    while (n!=0)
    {
      L.add(false);
      --n;
    }
    Collections.reverse(L);

    List<Boolean> res = new ArrayList<Boolean>();
   // for (int i = 0 ; i < R.size(); ++i)
     // res.add(false);

    int it = 0;

    while (R.get(0) == L.get(0))
    {
      res.add(false);
      R.remove(0);
      L.remove(0);
    }

    for (int i = 0; i< R.size(); ++i)
      res.add(true);

    long out = 0;
    it = 0;
    long add = 1;
    Collections.reverse(res);
    while (it < res.size())
    {
      if (res.get(it))
        out += add;
      add *= 2;
      ++it;
    }
    System.out.println(out);
  }

}


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

public class pr169D implements Runnable {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer str;

	public void solve() throws IOException {
		long l = nextLong();
		long r = nextLong();
		long x = l ^ r;
		long i = 1;
		while (x >= i)
			i *= 2;
		out.println(x > i ? x : i - 1);
	}

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

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

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

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

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (IOException e) {
		}
	}

	public static void main(String[] args) {
		new Thread(new pr169D()).start();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class A {
	public static BufferedReader in;
	public static PrintWriter out;

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

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}

	private static void solve() throws IOException {
		String[] line = in.readLine().split(" ");
		String l = Long.toBinaryString(Long.parseLong(line[0]));
		String r = Long.toBinaryString(Long.parseLong(line[1]));
		if(l.equals(r)){
			out.println(0);
			return;
		}
		int dif = r.length()-l.length();
		for(int i =0;i<dif;i++)
			l= "0"+l;
		int index=0;
		for(;index<r.length();index++){
			if(l.charAt(index)!=r.charAt(index))
				break;
		}
		long ret=1;
		for(int i=0;i<l.length()-index;i++)
			ret+=ret;
		ret--;
		out.println(ret);

	}

}


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

public class SolutionD {
   BufferedReader in;
   StringTokenizer str;
   PrintWriter out;
   String SK;

   String next() throws IOException {
      while ((str == null) || (!str.hasMoreTokens())) {
      SK = in.readLine();
      if (SK == null)
      return null;
      str = new StringTokenizer(SK);
      }
      return str.nextToken();
   }

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

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

   long nextLong() throws IOException {
      return Long.parseLong(next());
   }
   void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        //in = new BufferedReader(new FileReader("input.txt"));
        //out = new PrintWriter("output.txt");
        solve();
        out.close();
   }

   public static void main(String[] args) throws IOException {
      new SolutionD().run();
   }
   void solve() throws IOException {
        long l=Long.parseLong(next());
        long r=Long.parseLong(next());
        String low=Long.toBinaryString(l);
        String up=Long.toBinaryString(r);

        int n=low.length();
        int m=up.length();
        for(int i=0;i<m-n;i++){
             low="0"+low;
        }
        String ret="";
        boolean fu=false;
        boolean fd=false;
        boolean su=false;
        boolean sd=false;
        if(m>n){
             su=true;
             fd=true;
        }
        for(int i=0;i<m;i++){
           if(low.charAt(i)==up.charAt(i)){
                if(low.charAt(i)=='1'){
                     if(fd){
                          ret+="1";
                          fu=true;
                     }
                     else if(sd){
                          ret+="1";
                          su=true;
                     }
                     else ret+="0";
                }
                else{
                     if(fu){
                          ret+="1";
                          fd=true;
                     }
                     else if(su){
                          ret+="1";
                          sd=true;
                     }
                     else ret+="0";
                }
           }else{
                if(up.charAt(i)=='1'){
                     su=true;
                     fd=true;
                }

                ret+="1";
           }
        }

        out.println(Long.parseLong(ret, 2));

   }

}


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

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        long a,b;
        a = scn.nextLong();
        b = scn.nextLong();
        long diff = b -a , tot = 0;
        int ind = 0;
        while(true) {
            long res = (long)Math.pow(2.0, ind);
            if (res > b) break;
            if (((a>>ind) != (b>>ind)) || diff >= res)
                tot += res;
            ind++;
        }
        System.out.println(tot);
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class D {
	static long l, r;
	static long[][][][][] dp;
	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader();
		l = in.nextLong();
		r = in.nextLong();
		dp = new long[65][2][2][2][2];
		for(int i = 0 ; i < 65;i++)
		for(int j = 0 ; j < 2;j++)
		for(int k = 0 ; k < 2;k++)
		for(int a = 0 ; a<2;a++)
		dp[i][j][k][a][0]=dp[i][j][k][a][1]=-1;
		System.out.println(go(63, 0, 0, 0, 0));
	}

	public static long go(int i, int a1, int a2, int b1, int b2) {
		if(i==-1)return 0;
		if(dp[i][a1][a2][b1][b2]!=-1)
			return dp[i][a1][a2][b1][b2];

		int f1 = 3, f2 = 3;
		int bl = (int) ((l >> i)) & 1, br = (int) ((r >> i) & 1);
		if (a2 == 0 && br==0)
			f1 &= 1;
		if(a1 == 0 && bl==1)
			f1 &= 2;
		if (b2 == 0 && br==0)
			f2 &= 1;
		if(b1 == 0 && bl==1)
			f2 &= 2;
		long res = 0;
		for(int x = 0 ; x<2;x++){
			for(int y = 0 ; y<2;y++){
				if(((f1>>x)&1) == 1 &&((f2>>y)&1) == 1){
					res = Math.max(res, (((long)(x^y))<<i)+go(i-1,x>bl||a1==1?1:0,x<br||a2==1?1:0,y>bl||b1==1?1:0,y<br||b2==1?1:0));
				}
			}
		}
		return dp[i][a1][a2][b1][b2]=res;
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer st;

		public InputReader() throws IOException {
			in = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(in.readLine());
		}

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

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

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


import java.io.PrintWriter;
import java.util.Scanner;

public class D {

	public static void main(String [] args){
		Scanner cin = new Scanner(System.in);
		PrintWriter cout = new PrintWriter(System.out);
		long l = cin.nextLong(), r = cin.nextLong(), k = 1;
		if (l == r)cout.println(0);
		else {
			while (((r>>k)<<k)>l)k++;k--;
			cout.println(((r>>k)<<k)^(((r>>k)<<k)-1));
		}
		cout.flush();
	}

}


import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author vadimmm
 */
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 {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long l = in.nextLong();
        long r = in.nextLong();
        /*
        long max = 1;
        boolean good = false;
        for (int i = 0; i < 62; ++i) {
            max <<= 1;
            if (max > r) {
                max >>= 1;
                if (max >= l) {
                    good = true;
                }
                break;
            }
        }
        if (good) {
            if (max - 1 >= l)
                out.println(max ^ (max - 1));
            else
                out.println(max ^ r);
            return;
        }
        */
        boolean[][] answer = new boolean[2][100];
        int cur = 0;
        while (r > 0) {
            answer[0][cur] = (r % 2 != 0);
            ++cur;
            r >>= 1;
        }
        cur = 0;
        while (l > 0) {
            answer[1][cur] = (l % 2 != 0);
            ++cur;
            l >>= 1;
        }
        int old = -1;
        for (int i = 63; i >= 0; --i) {
            if (answer[0][i] && !answer[1][i]) {
                old = i;
                break;
            }
        }
        if (old == -1) {
            out.println(0);
            return;
        }
        long a = 1;
        for (int i = 0; i < old; ++i) {
            a <<= 1;
            a += 1;
        }
        out.println(a);
    }
}

class InputReader {

    private static BufferedReader bufferedReader;
    private static StringTokenizer stringTokenizer;

    public InputReader(InputStream inputStream) {
        bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        stringTokenizer = null;
    }

    public String next() {
        while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            try {
                stringTokenizer = new StringTokenizer(bufferedReader.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return stringTokenizer.nextToken();
    }

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

    }


import java.util.Scanner;

public class Main2 {

    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        long s = input.nextLong();
        long e = input.nextLong();
        System.out.println(count(s,e));
    }

    public static long count(long s,long e){
    	int ncount = 0;
    	long es = e;
    	while(es != 0){
    		es /= 2;
    		ncount++;
    	}
    	while(ncount >= 0){
    		if(((s>>ncount-1)&1) == 1 && ((e>>ncount-1)&1) == 0 || ((s>>ncount-1)&1) == 0 && ((e>>ncount-1)&1) == 1){
    			break;
    		}
    		ncount--;
    	}
    	if(ncount >= 0){
    		return (long)Math.pow(2, ncount)-1;
    	}else{
    		return 0;
    	}
    }

}


import java.util.*;

public class Code {
	public Code(){}
	public static void main(String args[]){
		Scanner QQQ=new Scanner(System.in);
		long l=QQQ.nextLong();
		long r=QQQ.nextLong();
		long ans=l^r;
		int a[]=new int [70];
		int b[]=new int [70];
		int n=0,m=0;
		while (l!=0){
			a[m]=(int)(l%2);
			l/=2;
			m++;
		}
		while (r!=0){
			b[n]=(int)(r%2);
			r/=2;
			n++;
		}
		m--;n--;
		long deg[]=new long [70];
		deg[0]=1;
		for (int i=1;i<=62;i++) deg[i]=deg[i-1]*2;
		for (int i=n;i>=0;i--)
			if (b[i]==1&&a[i]==0){
				System.out.println(deg[i+1]-1);
				return;
			}
		System.out.println(ans);
	}
}


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

public class ProblemD {
    InputReader in; PrintWriter out;
    void solve() {
        long l = in.nextLong();
        long r = in.nextLong();
        long ans = 0;
        boolean add = false;
        for (int k = 62; k >= 0; k--) {
            long cb = (1L << k);
            if ((l & cb) != (r & cb))
                add = true;
            if (add)
                ans += (1L << k);
        }
        out.println(ans);
    }

    ProblemD(){
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        try {
            if (oj) {
                in = new InputReader(System.in);
                out = new PrintWriter(System.out);
            }
            else {
                Writer w = new FileWriter("output.txt");
                in = new InputReader(new FileReader("input.txt"));
                out = new PrintWriter(w);
            }
        } catch(Exception e) {
            throw new RuntimeException(e);
        }
        solve();
        out.close();
    }
    public static void main(String[] args){
        new ProblemD();
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

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

    public InputReader(FileReader fr) {
        reader = new BufferedReader(fr);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


//Author: Patel Rag
//Java version "1.8.0_211"
import java.util.*;
import java.io.*;

public class Main
{
  static class FastReader
  {
    BufferedReader br;
    StringTokenizer st;

    public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); }

    String next()
    {
      while (st == null || !st.hasMoreElements())
      {
        try
        {
          st = new StringTokenizer(br.readLine());
        }
        catch (IOException  e)
        {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

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

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

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

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

    boolean nextBoolean() { return Boolean.parseBoolean(next()); }

    String nextLine()
    {
      String str = "";
      try
      {
        str = br.readLine();
      }
      catch (IOException e)
      {
        e.printStackTrace();
      }
      return str;
    }
  }
  static long modExp(long x, long n, long mod)    //binary Modular exponentiation
  {
    long result = 1;
    while(n > 0)
    {
        if(n % 2 == 1)
            result = (result%mod * x%mod)%mod;
        x = (x%mod * x%mod)%mod;
        n=n/2;
    }
    return result;
  }
  static long gcd(long a, long b)
  {
    if(a==0) return b;
    return gcd(b%a,a);
  }
  public static void main(String[] args)
  throws IOException
  {
    FastReader fr = new FastReader();
    int n = fr.nextInt();
    int q = fr.nextInt();
    long[] a = new long[n];
    long[] k = new long[q];
    for(int i = 0; i < n; i++) a[i] = fr.nextLong();
    for(int i = 0; i < q; i++) k[i] = fr.nextLong();
    long[] pre = new long[n];
    pre[0] = a[0];
    for(int i = 1; i < n; i++) pre[i] = pre[i-1] + a[i];
    long pd = 0;
    for(int i = 0; i < q; i++)
    {
      int l = 0;
      int r = n - 1;
      while(r > l)
      {
        int mid = (l + r) >> 1;

        if(pre[mid] - pd < k[i])
        {
          l = mid + 1;
        }
        else if(pre[mid] - pd > k[i])
        {
          r = mid - 1;
        }
        else
        {
          l = r = mid;
        }
      }
      int ans = 0;
      if(pre[l] - pd <= k[i])
      {
        ans = n - l - 1;
      }
      else
      {
        ans = n - l;
      }
      if(ans == 0) ans  = n;
      pd = pd + k[i];
      if(pd >= pre[n-1]) pd = 0;
      System.out.println(ans);
    }
  }
}
class pair
{
  public int first;
  public int second;
  public pair(int first,int second)
  {
    this.first = first;
    this.second = second;
  }
  public pair(pair p)
  {
    this.first = p.first;
    this.second = p.second;
  }
  public int first() { return first; }
  public int second() { return second; }
  public void setFirst(int first) { this.first = first; }
  public void setSecond(int second) { this.second = second; }
}
class myComp implements Comparator<pair>
{
  public int compare(pair a,pair b)
  {
    if(a.first != b.first) return (a.first - b.first);
    return (b.second - a.second);
  }
}
class BIT       //Binary Indexed Tree aka Fenwick Tree
{
  public long[] m_array;

  public BIT(long[] dat)
  {
    m_array = new long[dat.length + 1];
    Arrays.fill(m_array,0);
    for(int i = 0; i < dat.length; i++)
    {
      m_array[i + 1] = dat[i];
    }
    for(int i = 1; i < m_array.length; i++)
    {
      int j = i + (i & -i);
      if(j < m_array.length)
      {
        m_array[j] = m_array[j] + m_array[i];
      }
    }
  }

  public final long prefix_query(int i)
  {
    long result = 0;
    for(++i; i > 0; i = i - (i & -i))
    {
      result = result + m_array[i];
    }
    return result;
  }

  public final long range_query(int fro, int to)
  {
    if(fro == 0)
    {
      return prefix_query(to);
    }
    else
    {
      return (prefix_query(to) - prefix_query(fro - 1));
    }
  }

  public void update(int i, long add)
  {
    for(++i; i < m_array.length; i = i + (i & -i))
    {
      m_array[i] = m_array[i] + add;
    }
  }
}


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.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            TaskC.pair[] songs = new TaskC.pair[n];
            long sum = 0;
            for (int i = 0; i < n; i++) {
                songs[i] = new TaskC.pair(in.nextInt(), in.nextInt());
                sum += songs[i].a;
            }
            Arrays.sort(songs);

            int res = 0;
            int idx = n - 1;
            while (sum > m) {
                if (idx < 0) {
                    break;
                }
                sum -= (songs[idx].a - songs[idx].b);

                res++;
                idx--;
            }

            if (sum > m) {
                out.println(-1);
            } else {
                out.println(res);
            }
        }

        static class pair implements Comparable<TaskC.pair> {
            int a;
            int b;

            pair(int a, int b) {
                this.a = a;
                this.b = b;
            }

            public int compareTo(TaskC.pair p) {
                return (this.a - this.b) - (p.a - p.b);
            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}


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

public class CoveredPointsCount {

	//UPSOLVE

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());

		int n = Integer.parseInt(st.nextToken());

		long[] myArray = new long[2 * n];

			for (int i = 0; i < n; i++)  {
	        	StringTokenizer st1 = new StringTokenizer(br.readLine());
	        	myArray[2 * i] = Long.parseLong(st1.nextToken()) * 2;
	        	myArray[2 * i + 1] = Long.parseLong(st1.nextToken()) * 2 + 1;
	        }

	        Arrays.sort(myArray);
	        long[] ans = new long[n + 1];
	        int cnt = 0;

	        for (int i = 0; i < 2 * n - 1; i++)   {
	            if (myArray[i] % 2 == 0) cnt++; else cnt--;
	            ans[cnt] += (myArray[i + 1] + 1) / 2 - (myArray[i] + 1) / 2;
	        }

	        StringBuilder answer = new StringBuilder();

	        for (int i = 1; i < n + 1; i++) {
	        	answer.append(ans[i]);
	        	answer.append(" ");
	        }

	        System.out.println(answer);

	}

}


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

public class A {
    static int[] parent;

    public static int find(int x) {
        if (x == parent[x])
            return x;
        return parent[x] = find(parent[x]);
    }

    public static void union(int x, int y) {
        int px = find(x);
        int py = find(y);
        if (px != py) {
            parent[py] = px;
        }
    }

    public static void main(String[] args) throws Exception {
        int numCnt = (int) nextLong();
        long k = nextLong();
        parent = new int[numCnt];
        for (int i = 0; i < parent.length; i++) {
            parent[i] = i;
        }
        HashMap<Long, Integer> map = new HashMap<Long, Integer>();
        long[] ar = new long[numCnt];
        for (int i = 0; i < numCnt; i++) {
            ar[i] = nextLong();
            map.put(ar[i] * 10007 + ar[i] / 13, i);
        }
        for (int i = 0; i < ar.length; i++) {
            long req = ar[i] * k;
            Integer idx=map.get(req * 10007 + req / 13);
            if (idx!=null) {
                union(i, idx);
            }
        }
        int[] count = new int[numCnt];
        for (int i = 0; i < parent.length; i++) {
            count[find(i)]++;
        }
        int res = 0;
        for (int i = 0; i < numCnt; i++) {
            res += (int) ((count[i] + 1) / 2.0);
        }
        System.out.println(res);
    }

    static BufferedReader br = new BufferedReader(new InputStreamReader(
            System.in));
    static StringTokenizer tokenizer = new StringTokenizer("");

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

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

    static String next() throws Exception {
        while (true) {
            if (tokenizer.hasMoreTokens()) {
                return tokenizer.nextToken();
            }
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            tokenizer = new StringTokenizer(s);
        }
    }
}


// @author Sanzhar
import java.io.*;
import java.util.*;
import java.awt.Point;

public class Template {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;

    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(in.readLine());
            } catch (Exception e) {
            }
        }
        return st.nextToken();
    }

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

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

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

    public void run() throws Exception {
        //in = new BufferedReader(new FileReader("input.txt"));
        //out = new PrintWriter(new FileWriter("output.txt"));
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();
        in.close();
    }

    public void solve() throws Exception {
        int n = nextInt();
        int k = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        boolean[] ok = new boolean[n];
        Arrays.fill(ok, true);
        Arrays.sort(a);
        if (k != 1) {
            for (int i = 0; i < n; i++) {
                if (a[i] % k == 0) {
                    int x = a[i] / k;
                    int ind = Arrays.binarySearch(a, x);
                    if (ind >= 0 && ok[ind]) {
                        ok[i] = false;
                    }
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (ok[i]) {
                ans++;
            }
        }
        out.println(ans);
    }

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


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

public class Main
	{
	public static void main(String args[]) throws IOException
		{
		BufferedReader c=new BufferedReader(new InputStreamReader(System.in));
		String S[]=c.readLine().split(" ");
		int N=Integer.parseInt(S[0]);
		int K=Integer.parseInt(S[1]);
		int A[]=parseArray(c.readLine(),N);
		shuffle(A);
		Arrays.sort(A);

		TreeMap<Long,Long> T=new TreeMap<Long, Long>();
		int ans=0;
		for(int i=0;i<N;i++)
			T.put((long)A[i],1L);
		//System.out.println(Arrays.toString(A));
		if(K==1)
			{
			System.out.println(N);
			return;
			}
		else
			{
			for(int i=0;i<N;i++)
				{
				if(A[i]%K==0&&T.containsKey((long)A[i]/K))		//A[i] is not start of a chain
					continue;
				//System.out.println("considering "+A[i]);
				int chainSize=0;
				long init=A[i];
				while(T.containsKey(init))
					{
					chainSize++;
					init=init*K;
					}
				//System.out.println("\t"+chainSize);
				ans+=(chainSize+1)/2;
				}
			}
		System.out.println(ans);
		}
	/**
	 * Knuth's shuffle. Generate a random permutation of an array
	 */
	public static int[] shuffle(int A[])
		{
		int N=A.length;
		for(int i=1;i<N;i++)
			{
			int j=(int) (Math.random()*100000)%(i+1); // 0<=j<=i;
			int temp=A[i];
			A[i]=A[j];
			A[j]=temp;
			}
		return A;
		}
	// Parse an integer array of size N from a string s
	public static int[] parseArray(String s,int N)
		{
		int A[]=new int[N];
		StringTokenizer st=new StringTokenizer(s);
		for(int i=0;i<N;i++)
			A[i]=Integer.parseInt(st.nextToken());
		return A;
		}
	}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

//basically tried to understand ping's greedy alg
public class kMultRedo {
	static int n;
	static int k;
	public static void main(String[] args){

		//lol what?? If use HashSet timeout, but if use tree set, not?
		//even with super high initialize capacty = 100,000,where max 100000
		Set<Integer> set = new HashSet<Integer>(1000000);
		FastScanner s = new FastScanner();
		n = s.nextInt();
		k = s.nextInt();

		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = s.nextInt();
		}
		Arrays.sort(a);

		for(int i=0; i<n; i++){
			if(a[i]%k !=0){
				set.add(a[i]);
			}else{
				if(!set.contains(a[i]/k)){
					set.add(a[i]);
				}
			}
		}

		System.out.println(set.size());
	}

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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


import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Set;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.io.InputStream;

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

class TaskA {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        int n = in.nextInt();
        int k = in.nextInt();

        Integer[] a = new Integer[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        Set <Integer> vis = new TreeSet<Integer>();
        Arrays.sort(a);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (!(a[i] % k == 0 && vis.contains(a[i] / k))) {
                ++ans;
                vis.add(a[i]);
            }
        }

        out.println(ans);
    }
}

class Scanner {
    BufferedReader in;
    StringTokenizer tok;

    public Scanner(InputStream in) {
        this.in = new BufferedReader(new InputStreamReader(in));
        tok = new StringTokenizer("");
    }

    public String nextToken() {
        if (!tok.hasMoreTokens()) {
            try {
                String newLine = in.readLine();
                if (newLine == null)
                    throw new InputMismatchException();
                tok = new StringTokenizer(newLine);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            return nextToken();
        }

        return tok.nextToken();
    }

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

    }


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class A {

    static StringTokenizer st;
    static BufferedReader in;
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        int k = nextInt();
        Integer[]a = new Integer[n+1];
        for (int i = 1; i <= n; i++) {
            a[i] = nextInt();
        }
        if (k==1) {
            System.out.println(n);
            return;
        }
        Arrays.sort(a, 1, n+1);
        Set<Integer> set = new HashSet<Integer>();
        int ans = 0;
        int INF = (int) 1e9;
        for (int i = 1; i <= n; i++) {
            if (set.contains(a[i]))
                continue;
            int t = a[i];
            int s = 1;
            while ((long)t*k <= INF) {
                t *= k;
                if (Arrays.binarySearch(a, 1, n+1,  t) >= 0) {
                    set.add(t);
                    s++;
                }
                else
                    break;
            }
            if (s % 2==0)
                ans += s/2;
            else
                ans += s/2+1;
        }
        System.out.println(ans);
        pw.close();
    }
    private static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

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

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

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


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

public class CFJava {
    private static void println(Integer n) {
        System.out.println(n);
    }

    private static void println(String s) {
        System.out.println(s);
    }

    private static void print(Integer n) {
        System.out.print(n);
    }

    private static void print(String s) {
        System.out.print(s);
    }

    public static void main(String[] args) throws IOException {
        MyScanner scanner = new MyScanner();
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        Integer[] a = scanner.getIntArray(n);
        Arrays.sort(a);
        TreeSet<Integer> res = new TreeSet<Integer>();
        for (Integer i: a){
            if (!res.contains(i/k)||(i%k!=0))
                res.add(i);
        }
        println(res.size());
    }
}

class Pair {
    public int x;
    public int y;

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

class MyScanner {
    private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    private String[] buffer;
    private int pos = 0;

    public Integer nextInt() throws IOException {
        if (buffer == null) {
            buffer = in.readLine().split(" ");
            pos = 0;
        }
        if (buffer.length <= pos) {
            buffer = in.readLine().split(" ");
            pos = 0;
        }
        pos++;
        return Integer.parseInt(buffer[pos - 1]);
    }

    public String nextString() throws IOException {
        if (buffer == null) {
            buffer = in.readLine().split(" ");
            pos = 0;
        }
        if (buffer.length <= pos) {
            buffer = in.readLine().split(" ");
            pos = 0;
        }
        pos++;
        return buffer[pos - 1];
    }

    public ArrayList<Integer> getIntList(Integer n) throws IOException {
        ArrayList<Integer> result = new ArrayList<Integer>(n);
        for (int i = 0; i < n; i++)
            result.add(nextInt());
        return result;
    }

    public Integer[] getIntArray(Integer n) throws IOException {
        Integer[] result = new Integer[n];
        for (int i = 0; i < n; i++)
            result[i]= (nextInt());
        return result;
    }

}


import static java.math.BigInteger.*;
import static java.util.Arrays.*;

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

public class A {

	final int MOD = (int)1e9 + 7;
	final double eps = 1e-12;
	final int INF = (int)1e9;

	public A () {
		int N = sc.nextInt();
		int K = sc.nextInt();
		Long [] A = sc.nextLongs();

		sort(A);
		Set<Long> S = new HashSet<Long>();

		for (long a : A) {
			if (a % K == 0 && S.contains(H(a/K)))
				continue;
			S.add(H(a));
		}

		int res = S.size();
		exit(res);
	}

	long P = probablePrime(60, new Random()).longValue();
	long Q = probablePrime(60, new Random()).longValue();

	long H(long x) {
		return P*x + Q;
	}

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

	/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */

	static MyScanner sc = new MyScanner();

	static class MyScanner {
		public String next() {
			newLine();
			return line[index++];
		}

		public char nextChar() {
			return next().charAt(0);
		}

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

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

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

		public String nextLine() {
			line = null;
			return readLine();
		}

		public String [] nextStrings() {
			line = null;
			return readLine().split(" ");
		}

		public char [] nextChars() {
			return next().toCharArray();
		}

		public Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}

		public Long [] nextLongs() {
			String [] L = nextStrings();
			Long [] res = new Long [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Long.parseLong(L[i]);
			return res;
		}

		public Double [] nextDoubles() {
			String [] L = nextStrings();
			Double [] res = new Double [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Double.parseDouble(L[i]);
			return res;
		}

		public String [] next (int N) {
			String [] res = new String [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.next();
			return res;
		}

		public Integer [] nextInt (int N) {
			Integer [] res = new Integer [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextInt();
			return res;
		}

		public Long [] nextLong (int N) {
			Long [] res = new Long [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextLong();
			return res;
		}

		public Double [] nextDouble (int N) {
			Double [] res = new Double [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextDouble();
			return res;
		}

		public String [][] nextStrings (int N) {
			String [][] res = new String [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextStrings();
			return res;
		}

		public Integer [][] nextInts (int N) {
			Integer [][] res = new Integer [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextInts();
			return res;
		}

		public Long [][] nextLongs (int N) {
			Long [][] res = new Long [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextLongs();
			return res;
		}

		public Double [][] nextDoubles (int N) {
			Double [][] res = new Double [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextDoubles();
			return res;
		}

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

		private boolean eol() {
			return index == line.length;
		}

		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private final BufferedReader r;

		MyScanner () {
			this(new BufferedReader(new InputStreamReader(System.in)));
		}

		MyScanner(BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}

		private String [] line;
		private int index;

		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}

	static void print(Object o, Object... a) {
		printDelim(" ", o, a);
	}

	static void cprint(Object o, Object... a) {
		printDelim("", o, a);
	}

	static void printDelim (String delim, Object o, Object... a) {
		pw.println(build(delim, o, a));
	}

	static void exit (Object o, Object... a) {
		print(o, a);
		exit();
	}

	static void exit () {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}

	void NO() {
		throw new Error("NO!");
	}

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

	static String build(String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.toString().trim();
	}

	static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>) {
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		} else
			b.append(delim).append(o);
	}

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

	public static void main(String[] args) {
		new A();
		exit();
	}

	static void start() {
		t = millis();
	}

	static PrintWriter pw = new PrintWriter(System.out);

	static long t;

	static long millis() {
		return System.currentTimeMillis();
	}
}


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

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void run() {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = in.nextInt(), k = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; ++i)
			a[i] = in.nextInt();
		Arrays.sort(a);
		int ret = 0, it = 0;
		for (int i = 0; i < n; ++i) {
			int val = a[i] % k == 0 ? a[i] / k : -1;
			while (it < i && a[it] < val) ++it;
			if (it == i || a[it] != val) {
				++ret;
			}
			else {
				a[i] = 0;
			}
		}
		out.println(ret);

		out.close();
	}
}

class InputReader {
	BufferedReader buff;
	StringTokenizer tokenizer;

	InputReader(InputStream stream) {
		buff = new BufferedReader(new InputStreamReader(stream));
		tokenizer = null;
	}
	boolean hasNext() {
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			try {
				tokenizer = new StringTokenizer(buff.readLine());
			}
			catch (Exception e) {
				return false;
			}
		return true;
	}
	String next() {
		if (!hasNext())
			throw new RuntimeException();
		return tokenizer.nextToken();
	}
	int nextInt() { return Integer.parseInt(next()); }
	long nextLong() { return Long.parseLong(next()); }
}


import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author sheep
 */
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);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int k = in.nextInt();
        HashSet<Integer> set = new HashSet<Integer>();
        int a[] = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        int ans = 0;
        int ptr = -1;
        boolean chosen[] = new boolean[n];
        for (int i = 0; i < n; ++i) {
            while (ptr + 1 < i && a[ptr + 1] * (long)k <= a[i]) {
                ++ptr;
            }

            if (a[i] % k != 0 || ptr == -1 || !chosen[ptr] || a[ptr] * (long)k != a[i]) {
                ++ans;
                chosen[i] = true;
            }
        }

        out.println(ans);
    }
}

class InputReader {
    BufferedReader reader;
    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 (Exception e) {
                throw new UnknownError();
            }
        }
        return tokenizer.nextToken();
    }

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

    }


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

public class A {
    public static void main(String[] args) throws Exception {
        new A().solve();
        // new FileInputStream(new File("input.txt")),
        // new PrintStream(new FileOutputStream(new File("output.txt"))));
    }

    void solve() throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        // Scanner sc = new Scanner(System.in);
        String[] sp;

        sp = in.readLine().split(" ");
        int n = Integer.parseInt(sp[0]);
        long k = Integer.parseInt(sp[1]);
        Long[] a = new Long[n];
        sp = in.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            a[i] = (long) Integer.parseInt(sp[i]);
        }

        Arrays.sort(a);
        TreeSet<Long> set = new TreeSet<Long>();
        for (int i = 0; i < n; i++) {
            long x = a[i];
            if (!set.contains(x)) {
                set.add(x * k);
            }
        }
        System.out.println(set.size());
    }
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//


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

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class  test{

	// ArrayList<Integer> lis = new ArrayList<Integer>();
	// ArrayList<String> lis = new ArrayList<String>();
	//  PriorityQueue<P> que = new PriorityQueue<P>();
	// PriorityQueue<Integer> que = new PriorityQueue<Integer>();
	//  Stack<Integer> que = new Stack<Integer>();
    //	static long sum=0;
	// 1000000007 (10^9+7)
	static int mod = 1000000007;
	//static int mod = 1000000009,r=0;
   // static int dx[]={1,-1,0,0};
//	static int dy[]={0,0,1,-1};
//	static int dx[]={1,-1,0,0,1,1,-1,-1};
//  static int dy[]={0,0,1,-1,1,-1,1,-1};
	//static long H,L;
	//static Set<Integer> set = new HashSet<Integer>();
public  static void main(String[] args)   throws Exception, IOException{
   //String line=""; throws Exception, IOException
   //(line=br.readLine())!=null
	//Scanner sc =new Scanner(System.in);
	// !!caution!! int long //
	Reader sc = new Reader(System.in);
  // while( ){
	  // int  n=sc.nextInt(),m=sc.nextInt();//a[]=new int[n],b[]=new int[n];
	int  n=sc.nextInt(),r=0;long k=sc.nextInt();
    Integer x[]=new Integer[n];
	 boolean b[]=new boolean[n];

   for(int i=0;i<n;i++){
	   x[i]=sc.nextInt();
  }
   if( k==1 ){System.out.println(n); return;}
   sort(x);

   for(int i=0;i<n;i++){
	 if( b[i] )continue;
	 r++;
	 long p=x[i],pr=x[i];
	 while( p*k<=x[n-1] ) {p*=k;

	 int up=n,dw=0,mid=(up+dw)/2;
	 boolean f=false;
	 while( up-dw!=1 ){
		 //db(p,x[mid]);
		 if( x[mid]==p ){f=true;break;}
		 if( p<x[mid] ){ up=mid; mid=(up+dw)/2; }
		 else { dw=mid; mid=(up+dw)/2; }
	 }
	  if( f ){ if(pr*k!=p){r++; pr=p;}   b[mid]=true;  }
	  }

  }

    System.out.println(r);

}

static void db(Object... os){
    System.err.println(Arrays.deepToString(os));

}

}

class Reader
{
	private BufferedReader x;
	private StringTokenizer st;

	public Reader(InputStream in)
	{
		x = new BufferedReader(new InputStreamReader(in));
		st = null;
	}
	public String nextString() throws IOException
	{
		while( st==null || !st.hasMoreTokens() )
			st = new StringTokenizer(x.readLine());
		return st.nextToken();
	}
	public int nextInt() throws IOException
	{
		return Integer.parseInt(nextString());
	}
	public long nextLong() throws IOException
	{
		return Long.parseLong(nextString());
	}
	public double nextDouble() throws IOException
	{
		return Double.parseDouble(nextString());
	}
}

/*

class P implements Comparable<P>{
	int x,y;
	P(int x,int y){ this.x=x; this.y=y;  }

	public int compareTo(P z) {
	 if( x-z.x!=0)   return  x-z.x ;  //ascend
	 else return  y-z.y ;
	}
}
//*/


import java.util.*;
import java.io.*;
public class a {
public static void main(String[] args) throws IOException
{
    input.init(System.in);
    int n = input.nextInt(), k = input.nextInt();
    TreeSet<Integer> ts = new TreeSet<Integer>();
    int[] data = new int[n];
    for(int i = 0; i<n; i++)
    {
        data[i] = input.nextInt();
    }
    Arrays.sort(data);
    if(n>1 && k==1.*data[n-1]/data[0])
        System.out.println(n-1);
    else
    {
    for(int i = 0; i<n; i++)
    {
        if(data[i]%k != 0)
            ts.add(data[i]);
        else
        {
            if(!ts.contains(data[i]/k))
                ts.add(data[i]);
        }
    }
    System.out.println(ts.size());
    }
}
public static class input {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

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

    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.TreeSet;

public class Main {

	public static void main(String [] args ) {
		try{
			String str;
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			BufferedOutputStream bos = new BufferedOutputStream(System.out);
			String eol = System.getProperty("line.separator");
			byte [] eolb = eol.getBytes();
			byte[] spaceb= " ".getBytes();

			str  = br.readLine();
			int blank = str.indexOf( " ");
			int n = Integer.parseInt(str.substring(0,blank));
			int m = Integer.parseInt(str.substring(blank+1));
			long [] num = new long[n];
			int j=0;
			int s=0;
			int k =0;
			str = br.readLine();
			int length = str.length();
			while(j<length) {
				while(j<length) {
					if(str.charAt(j) == ' ') {
						break;
					}else {
						j++;
					}
				}
				num[k] = Long.parseLong(str.substring(s,j)) ;
				k++;
				j++;
				s=j;
			}
			Arrays.sort(num);
			int count = 0;
			if(m==1) {
				count = 1;
				for(int i = 1 ; i < n ; i++) {
					if(num[i]!=num[i-1]) {
						count++;
					}
				}
			} else {
				TreeSet<Long> take = new TreeSet<Long>();
				TreeSet<Long> notTake = new TreeSet<Long>();
				for(int i = 0 ; i < n ; i++) {
					long temp = num[i];
					if(!notTake.contains(temp)){
						take.add(temp);
						temp *= ((long)m);
						notTake.add(temp);
					}

				}
				count = take.size();
			}
			bos.write(new Integer(count).toString().getBytes());
			bos.write(eolb);
			bos.flush();
		}  catch(IOException ioe) {
			ioe.printStackTrace();
		}
	}
}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Locale;
import java.io.OutputStream;
import java.util.RandomAccess;
import java.io.PrintWriter;
import java.util.AbstractList;
import java.io.Writer;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.TreeMap;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Jacob Jiang
 */
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);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.nextInt();
        long k = in.nextInt();
        if (k == 1) {
            out.println(n);
            return;
        }
        long[] a = in.nextLongArray(n);
        ArrayUtils.safeSort(a);
        Map<Long, Integer> map = new TreeMap<Long, Integer>();
        for (int i = 0; i < n; i++) {
            map.put(a[i], i);
        }
        int answer = 0;
        boolean[] visited = new boolean[n];
        for (int i = 0; i < n; i++) {
            if (!visited[i]) {
                visited[i] = true;
                int count = 1;
                long cur = a[i];
                while (true) {
                    cur *= k;
                    Integer index = map.get(cur);
                    if (index == null)
                        break;
                    visited[index] = true;
                    count++;
                }
                answer += NumberUtils.upDiv(count, 2);
            }
        }
        out.println(answer);
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1 << 16];
    private int curChar;
    private int numChars;

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

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

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

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

    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 & 15;
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long[] nextLongArray(int count) {
        long[] result = new long[count];
        for (int i = 0; i < count; i++) {
            result[i] = nextLong();
        }
        return result;
    }

    }

class OutputWriter {
    private PrintWriter writer;

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

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

    public void println(int i) {
        writer.println(i);
    }

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

    }

class ArrayUtils {

    public static List<Long> asList(long[] array) {
        return new LongList(array);
    }

    private static class LongList extends AbstractList<Long> implements RandomAccess {
        long[] array;

        private LongList(long[] array) {
            this.array = array;
        }

        public Long set(int index, Long element) {
            long result = array[index];
            array[index] = element;
            return result;
        }

        public Long get(int index) {
            return array[index];
        }

        public int size() {
            return array.length;
        }
    }

    public static void safeSort(long[] array) {
        Collections.shuffle(asList(array));
        Arrays.sort(array);
    }

    }

class NumberUtils {
    public static int upDiv(int a, int b) {
        return a % b == 0 ? (a / b) : (a / b + 1);
    }

    }


import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Class<?> here = new Object(){}.getClass().getEnclosingClass();
		try {
			String packageName = here.getPackage().getName();
			packageName = "src/" + packageName.replaceAll("\\.", "/") + "/";
			System.setIn(new FileInputStream(packageName + "input.txt"));
//			System.setOut(new PrintStream(new FileOutputStream(packageName + "output.txt")));
		} catch (FileNotFoundException e) {
		} catch (NullPointerException e) {
		}

		Object o = Class.forName(here.getName()).newInstance();
		o.getClass().getMethod("run").invoke(o);
	}

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	void solve() {
		int n = sc.nextInt();
		int k = sc.nextInt();

		TreeSet<Integer> at = new TreeSet<Integer>();
		for (int i = 0; i < n; i++) at.add(sc.nextInt());
		Integer[] ai = at.toArray(new Integer[0]);
		int[] a = new int[n];
		for (int i = 0; i < n; i++) a[i] = ai[i];

		if (k == 1) {
			out.println(n);
			return;
		}

		boolean[] invalid = new boolean[n];

		tr(a);
		int ans = 0;
		for (int i = 0, j = 0; i < n; i++) if (!invalid[i]) {
			++ans;
			long kx = (long)k * a[i];
			while (j < n && a[j] < kx) {
				j++;
			}
			if (j < n && kx == a[j]) {
				invalid[j] = true;
			}
		}
		out.println(ans);

	}

	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

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

		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}

		public String next() {
			eat();
			return tokenizer.nextToken();
		}

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

		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}

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

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

		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}


import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class A {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void solve() throws IOException {
		int n = readInt();
		long k = readInt();
		Long[] a = new Long[n];
		for(int i = 0; i < n; i++){
			a[i] = readLong();
		}
		Arrays.sort(a);
		TreeSet<Long> set = new TreeSet<Long>();
		for(int i = 0; i < n; i++){
			set.add(a[i]);
		}
		if(k == 1) {
			out.println(n);
			return;
		}
		int res = 0;
		TreeSet<Long> used = new TreeSet<Long>();
		for(Long cur: set){
			if(!used.contains(cur)){
				int num = 1;
				used.add(cur);
				Long temp = cur * 1;

				while(true){
					if(set.contains(k*temp)){
						num++;
						used.add(k*temp);
						temp *= k;
					}
					else{
						res += (num+1)/2;
						break;
					}
				}
			}
		}
		out.println(res);

    }

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

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

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readArr(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long[] readArrL(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = readLong();
        }
        return res;
    }

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

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }
}


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

public class solve {
	Scanner in;
	PrintWriter out;

	public void solve() throws IOException {
		int n = in.nextInt();
		long k = in.nextLong();
		int[] a = new int[n];
		Set<Long> b = new TreeSet<Long>();
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		Arrays.sort(a);
		int ans = 0;
		for (int i = n - 1; i >= 0; i--) {
			if (!b.contains((long) k * a[i])) {
				ans++;
				b.add((long) a[i]);
			}
		}
		out.print(ans);
	}

	public void run() {
		try {
			in = new Scanner(System.in);
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

	public static void main(String[] arg) {
		new solve().run();
	}
}


import java.io.DataInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;

public class div168C {

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

    div168C a=new div168C();
        Parserdoubt pd=a.new Parserdoubt(System.in);
        StringBuffer sb = new StringBuffer();

        ArrayList<Integer> arr=new ArrayList<Integer>();
        int max=0;
        int n=pd.nextInt();
        int k=pd.nextInt();
        for(int i=0;i<n;i++){
            arr.add(pd.nextInt());
            max=Math.max(max, arr.get(i));
        }
        Collections.sort(arr);

        int count=0;
        int[] mat=new int[n+1];
        for(int i=n-1;i>=0;i--){
            if(mat[i]!=1){
                int x=arr.get(i);
                if(x%k==0){
                int ans=Collections.binarySearch(arr, x/k);

            //  System.out.println("index "+ans);

                if(ans>=0&&arr.get(ans)==(x/k)){
                    count++;
                    mat[ans]=1;
                }
                else{
                    count++;
                }
                }
                else{
                    count++;
                }
            }
        }
        /*for(int i=0;i<arr.size();i++){
            System.out.print(arr.get(i)+" ");
        }
        System.out.println();
        */
        if(n==1)
            count=1;
        System.out.println(count);

}

class Parserdoubt
{
   final private int BUFFER_SIZE = 1 << 17;

   private DataInputStream din;
   private byte[] buffer;
   private int bufferPointer, bytesRead;

   public Parserdoubt(InputStream in)
   {
      din = new DataInputStream(in);
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
   }
   public String nextString() throws Exception
   {
       StringBuffer sb=new StringBuffer("");
       byte c = read();
       while (c <= ' ') c = read();
       do
       {
           sb.append((char)c);
           c=read();
       }while(c>' ');
       return sb.toString();
   }
   public char nextChar() throws Exception
   {
       byte c=read();
       while(c<=' ') c= read();
       return (char)c;
   }
   public int nextInt() throws Exception
   {
      int ret = 0;
      byte c = read();
      while (c <= ' ') c = read();
      boolean neg = c == '-';
      if (neg) c = read();
      do
      {
          ret = ret * 10 + c - '0';
         c = read();
      } while (c > ' ');
      if (neg) return -ret;
      return ret;
   }
   public long nextLong() throws Exception
   {
      long ret = 0;
      byte c = read();
      while (c <= ' ') c = read();
      boolean neg = c == '-';
      if (neg) c = read();
      do
      {
          ret = ret * 10 + c - '0';
         c = read();
      } while (c > ' ');
      if (neg) return -ret;
      return ret;
   }
   private void fillBuffer() throws Exception
   {
      bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
      if (bytesRead == -1) buffer[0] = -1;
   }

   private byte read() throws Exception
   {
      if (bufferPointer == bytesRead) fillBuffer();
      return buffer[bufferPointer++];
   }
}

}