import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

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);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }

    static class TaskB {
        public void solve( InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int x = in.nextInt();
            int[] arr = new int[n];
            int[] freq = new int[100000+1];
            boolean[] and = new boolean[100000+1];
            for (int i = 0; i <n ; i++) {
                arr[i]=in.nextInt();
                freq[arr[i]]++;
            }
            int min = 0;
            boolean ok = false;
            for (int i = 0; i <arr.length ; i++){
                if (freq[arr[i]] > 1){
                    ok = true;
                    break;
                }
            }
            if (ok){
                out.println(min);
                return;
            }
            for (int i = 0; i <n ; i++){
                if (and[arr[i]]=false){
                    min=1;
                    and[arr[i]]=true;
                }
                else min=2;
                freq[arr[i]]--;
                freq[(arr[i]&x)]++;
                if ((freq[(arr[i]&x)]>1)){
                    ok=true;
                    break;
                }
            }
            if (ok){
                out.println(min);
                return;
            }
            out.println(-1);

        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

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);
        TaskC solver = new TaskC();
        solver.solve(in, out);
        out.close();
    }

    static class TaskC {
        public void solve( InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int x = in.nextInt();
            int[] arr = new int[n];
            int[] freq = new int[100000+1];
            boolean[] and = new boolean[100000+1];
            for (int i = 0; i <n ; i++) {
                arr[i]=in.nextInt();
                freq[arr[i]]++;
            }
            int min = 0;
            boolean ok = false;
            for (int i = 0; i <arr.length ; i++){
                if (freq[arr[i]] > 1){
                    ok = true;
                    break;
                }
            }
            if (ok){
                out.println(min);
                return;
            }
            min=1;
            for (int i = 0; i <n; i++){
                freq[arr[i]]--;
                int v = (arr[i]&x);
                freq[v]++;
                if (freq[v] > 1){
                    ok=true;
                    break;
                }
                freq[arr[i]]++;
                freq[v]--;
            }
            if (ok){
                out.println(min);
                return;
            }
            min = 2;
            for (int i = 0; i <arr.length ; i++) {
                freq[arr[i]]--;
                freq[(arr[i]&x)]++;
                if (freq[(arr[i]&x)] > 1){
                    ok = true;
                    break;
                }
            }
            if (ok){
                out.println(min);
                return;
            }
            out.println(-1);

        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

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);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }

    static class TaskB {
        public void solve( InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int x = in.nextInt();
            int[] arr = new int[n];
            int[] freq = new int[100000+1];
            for (int i = 0; i <n ; i++) {
                arr[i]=in.nextInt();
                freq[arr[i]]++;
            }
            int min = 0;
            boolean ok = false;
            for (int i = 1; i <freq.length ; i++) {
                if (freq[i] > 1){
                    ok = true;
                    break;
                }
            }
            if (ok){
                out.println(min);
                return;
            }
            min = 1;
            Arrays.fill(freq , 0);
            for (int i = 0; i <n ; i++) {
                freq[(arr[i]&x)]++;
            }
            for (int i = 0; i <freq.length; i++) {
                if (freq[i] > 1){
                    ok=true;
                    break;
                }
            }
            if (ok){
                out.println(1);
                return;
            }
            out.println(-1);

        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }

}


import java.util.Scanner;

public class CF1012B {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] arr = new int[n];
		int[] freq = new int[100100];
		for(int i=0; i<n; i++) {
			arr[i] = sc.nextInt();
			freq[arr[i]]++;
		}
		boolean has = false;
		for(int i=0; i<n; i++)
			if(freq[arr[i]]>=2) {
				has = true;
				break;
			}
		if(has) System.out.println("0");
		else {
			int[] m = new int[n];
			for(int i=0; i<n; i++) m[i] = arr[i]&x;
			for(int i=0; i<n; i++)
				if(arr[i]!=m[i] && freq[m[i]]>=1) {
					has = true;
					break;
				}
			System.out.println(has ? "1" : "-1");
		}
	}
}


import java.util.Scanner;

public class CF1012B {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] arr = new int[n];
		int[] freq = new int[100100];
		for(int i=0; i<n; i++) {
			arr[i] = sc.nextInt();
			freq[arr[i]]++;
		}
		boolean has = false;
		for(int i=0; i<n; i++)
			if(freq[arr[i]]>=2) {
				has = true;
				break;
			}
		if(has) System.out.println("0");
		else {
			int[] m = new int[n];
			for(int i=0; i<n; i++) m[i] = arr[i]&x;
			for(int i=0; i<n; i++)
				if(arr[i]!=m[i] && freq[m[i]]>=1) {
					has = true;
					break;
				}
			if(has) System.out.println("1");
			else {
				int[] modFreq = new int[100100];
				for(int i=0; i<n; i++) modFreq[m[i]]++;
				for(int i=0; i<n; i++)
					if(modFreq[arr[i]]>=2) {
						has = true;
						break;
					}
				System.out.println(has ? "2" : "-1");
			}
		}
	}
}


import java.util.Scanner;

public class CF1012B {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] arr = new int[n];
		int[] freq = new int[100100];
		for(int i=0; i<n; i++) {
			arr[i] = sc.nextInt();
			freq[arr[i]]++;
		}
		boolean has = false;
		for(int i=0; i<n; i++)
			if(freq[arr[i]]>=2) {
				has = true;
				break;
			}
		if(has) System.out.println("0");
		else {
			int[] m = new int[n];
			for(int i=0; i<n; i++) m[i] = arr[i]&x;
			for(int i=0; i<n; i++)
				if(arr[i]!=m[i] && freq[m[i]]>=1) {
					has = true;
					break;
				}
			if(has) System.out.println("1");
			else {
				int[] modFreq = new int[100100];
				for(int i=0; i<n; i++) modFreq[m[i]]++;
				for(int i=0; i<n; i++)
					if(modFreq[m[i]]>=2) {
						has = true;
						break;
					}
				System.out.println(has ? "2" : "-1");
			}
		}
	}
}


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

public class Main
{

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        int n = in.nextInt();
        int k = in.nextInt();
        int[]a= new int[n];
        int[]nums = new int[100001];
        for (int i =0;i<n;i++) {
            a[i] = in.nextInt();
            nums[a[i]]++;
        }
        int ans=-1;
        for (int i =0;i<n;i++)
        {
            nums[a[i]]--;
            if (nums[a[i]]>0) {
                ans = 0;
                break;
            }
            nums[a[i]]++;
        }
        if (ans==-1)
        for (int i =0;i<n;i++)
        {
            nums[a[i]]--;
            if (nums[a[i]%k]>0) {
                ans = 1;
                break;
            }
            nums[a[i]]++;
        }
        if (ans==-1)
        {
            nums = new int[100001];
            for (int i =0;i<n;i++) {
                a[i] %= k;
                nums[a[i]]++;
            }
            for (int i =0;i<n;i++)
            {
                nums[a[i]]--;
                if (nums[a[i]%k]>0) {
                    ans = 2;
                    break;
                }
                nums[a[i]]++;
            }
        }
        out.printLine(ans);

        out.flush();
    }
    static void MergeSort(int[] a, int[] b,  int p, int r)
    {
        if (p < r)
        {
            int q = (r + p) / 2;
            MergeSort(a, b,  p, q);
            MergeSort(a, b, q + 1, r);
            Merge(a, b,  p, q, r);
        }
    }
    static void Merge(int[] a, int[] b,  int p, int q, int r)
    {
        int n1 = q - p + 1;
        int n2 = r - q;
        int[] R = new int[n1 + 1];
        int[] L = new int[n2 + 1];
        int[] R1 = new int[n1];
        int[] L1 = new int[n2];
        for (int i = 0; i < n1; i++)
        {
            R[i] = a[p + i];
            R1[i] = b[p + i];

        }
        R[n1] = Integer.MAX_VALUE;
        for (int i = 0; i < n2; i++)
        {
            L[i] = a[q + i + 1];
            L1[i] = b[q + i + 1];

        }
        L[n2] =Integer.MAX_VALUE;
        int n = a.length;
        int j = 0;
        int k = 0;
        for (int i = p; i <= r; i++)
        {
            if (L[j] < R[k])
            {
                a[i] = L[j];
                b[i] = L1[j];

                j++;
            }
            else
            {
                a[i] = R[k];
                b[i] = R1[k];

                k++;
            }

        }
    }
}

class pair  implements Comparable
{

    int key;
    int value;
    public pair(Object key, Object value) {

        this.key = (int)key;
        this.value=(int)value;
    }

    @Override
    public int compareTo(Object o) {
        pair temp =(pair)o;
        return  key-temp.key;
    }
}
class Graph {

    int n;
    ArrayList<Integer>[] adjList;

    public Graph(int n) {
        this.n = n;
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new ArrayList<>();
    }

}

class InputReader {

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

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

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

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

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

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

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

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

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

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

}

class OutputWriter {
    private final PrintWriter writer;

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

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

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

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

}


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

public class Main
{

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        int n = in.nextInt();
        int k = in.nextInt();
        int[]a= new int[n];
        int[]nums = new int[100001];
        for (int i =0;i<n;i++) {
            a[i] = in.nextInt();
            nums[a[i]]++;
        }
        int ans=-1;
        for (int i =0;i<n;i++)
        {
            nums[a[i]]--;
            if (nums[a[i]]>0) {
                ans = 0;
                break;
            }
            nums[a[i]]++;
        }
        if (ans==-1)
        for (int i =0;i<n;i++)
        {
            nums[a[i]]--;
            if (nums[a[i]^k]>0) {
                ans = 1;
                break;
            }
            nums[a[i]]++;
        }
        if (ans==-1)
        {
            nums = new int[100001];
            for (int i =0;i<n;i++) {
                a[i] ^= k;
                nums[a[i]]++;
            }
            for (int i =0;i<n;i++)
            {
                nums[a[i]]--;
                if (nums[a[i]^k]>0) {
                    ans = 2;
                    break;
                }
                nums[a[i]]++;
            }
        }
        out.printLine(ans);

        out.flush();
    }
    static void MergeSort(int[] a, int[] b,  int p, int r)
    {
        if (p < r)
        {
            int q = (r + p) / 2;
            MergeSort(a, b,  p, q);
            MergeSort(a, b, q + 1, r);
            Merge(a, b,  p, q, r);
        }
    }
    static void Merge(int[] a, int[] b,  int p, int q, int r)
    {
        int n1 = q - p + 1;
        int n2 = r - q;
        int[] R = new int[n1 + 1];
        int[] L = new int[n2 + 1];
        int[] R1 = new int[n1];
        int[] L1 = new int[n2];
        for (int i = 0; i < n1; i++)
        {
            R[i] = a[p + i];
            R1[i] = b[p + i];

        }
        R[n1] = Integer.MAX_VALUE;
        for (int i = 0; i < n2; i++)
        {
            L[i] = a[q + i + 1];
            L1[i] = b[q + i + 1];

        }
        L[n2] =Integer.MAX_VALUE;
        int n = a.length;
        int j = 0;
        int k = 0;
        for (int i = p; i <= r; i++)
        {
            if (L[j] < R[k])
            {
                a[i] = L[j];
                b[i] = L1[j];

                j++;
            }
            else
            {
                a[i] = R[k];
                b[i] = R1[k];

                k++;
            }

        }
    }
}

class pair  implements Comparable
{

    int key;
    int value;
    public pair(Object key, Object value) {

        this.key = (int)key;
        this.value=(int)value;
    }

    @Override
    public int compareTo(Object o) {
        pair temp =(pair)o;
        return  key-temp.key;
    }
}
class Graph {

    int n;
    ArrayList<Integer>[] adjList;

    public Graph(int n) {
        this.n = n;
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new ArrayList<>();
    }

}

class InputReader {

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

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

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

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

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

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

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

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

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

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

}

class OutputWriter {
    private final PrintWriter writer;

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

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

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

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

}


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

public class Main
{

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        int n = in.nextInt();
        int k = in.nextInt();
        int[]a= new int[n];
        int[]nums = new int[100001];
        for (int i =0;i<n;i++) {
            a[i] = in.nextInt();
            nums[a[i]]++;
        }
        int ans=-1;
        for (int i =0;i<n;i++)
        {
            nums[a[i]]--;
            if (nums[a[i]]>0) {
                ans = 0;
                break;
            }
            nums[a[i]]++;
        }
        if (ans==-1)
        for (int i =0;i<n;i++)
        {
            nums[a[i]]--;
            if (nums[a[i]&k]>0) {
                ans = 1;
                break;
            }
            nums[a[i]]++;
        }
        if (ans==-1)
        {
            nums = new int[100001];
            for (int i =0;i<n;i++) {
                a[i] &= k;
                nums[a[i]]++;
            }
            for (int i =0;i<n;i++)
            {
                nums[a[i]]--;
                if (nums[a[i]&k]>0) {
                    ans = 2;
                    break;
                }
                nums[a[i]]++;
            }
        }
        out.printLine(ans);

        out.flush();
    }
    static void MergeSort(int[] a, int[] b,  int p, int r)
    {
        if (p < r)
        {
            int q = (r + p) / 2;
            MergeSort(a, b,  p, q);
            MergeSort(a, b, q + 1, r);
            Merge(a, b,  p, q, r);
        }
    }
    static void Merge(int[] a, int[] b,  int p, int q, int r)
    {
        int n1 = q - p + 1;
        int n2 = r - q;
        int[] R = new int[n1 + 1];
        int[] L = new int[n2 + 1];
        int[] R1 = new int[n1];
        int[] L1 = new int[n2];
        for (int i = 0; i < n1; i++)
        {
            R[i] = a[p + i];
            R1[i] = b[p + i];

        }
        R[n1] = Integer.MAX_VALUE;
        for (int i = 0; i < n2; i++)
        {
            L[i] = a[q + i + 1];
            L1[i] = b[q + i + 1];

        }
        L[n2] =Integer.MAX_VALUE;
        int n = a.length;
        int j = 0;
        int k = 0;
        for (int i = p; i <= r; i++)
        {
            if (L[j] < R[k])
            {
                a[i] = L[j];
                b[i] = L1[j];

                j++;
            }
            else
            {
                a[i] = R[k];
                b[i] = R1[k];

                k++;
            }

        }
    }
}

class pair  implements Comparable
{

    int key;
    int value;
    public pair(Object key, Object value) {

        this.key = (int)key;
        this.value=(int)value;
    }

    @Override
    public int compareTo(Object o) {
        pair temp =(pair)o;
        return  key-temp.key;
    }
}
class Graph {

    int n;
    ArrayList<Integer>[] adjList;

    public Graph(int n) {
        this.n = n;
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new ArrayList<>();
    }

}

class InputReader {

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

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

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

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

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

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

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

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

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

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

}

class OutputWriter {
    private final PrintWriter writer;

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

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

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

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

}


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

public class and
{
	public static void main(String args[])throws IOException
	{
		BufferedReader BR=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(BR.readLine());
		int n=Integer.parseInt(st.nextToken());
		int x=Integer.parseInt(st.nextToken());

		StringTokenizer st1=new StringTokenizer(BR.readLine());

		ArrayList<Integer> arr=new ArrayList<Integer>();
		ArrayList<Integer> arr1=new ArrayList<Integer>();
		int c=-1;
		for(int i=0;i<n;i++)
		{
			int y=Integer.parseInt(st1.nextToken());
			int j=y&x;

			if(arr.contains(y))
				{
					c=0;
					break;
				}
			if (arr1.contains(y) || arr.contains(j))
			{
				c=1;
				break;
			}

			if (arr1.contains(j))
			{
				c=2;
				break;
			}

			arr.add(y);
			arr1.add(j);

		}
		System.out.println(c);

	}
}


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

public class and
{
	public static void main(String args[])throws IOException
	{
		BufferedReader BR=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(BR.readLine());
		int n=Integer.parseInt(st.nextToken());
		int x=Integer.parseInt(st.nextToken());

		StringTokenizer st1=new StringTokenizer(BR.readLine());

		ArrayList<Integer> arr=new ArrayList<Integer>();
		ArrayList<Integer> arr1=new ArrayList<Integer>();
		int c=-1;
		for(int i=0;i<n;i++)
		{
			int y=Integer.parseInt(st1.nextToken());
			if(arr.contains(y))
				{
					c=0;
					break;
				}
			else if (arr1.contains(y))
			{
				c=1;
				break;
			}

			int j=y&x;

			if(arr.contains(j))
			{
				c=1;
				break;
			}
			else if (arr1.contains(j))
			{
				c=2;
				break;
			}

			arr.add(y);
			arr1.add(j);

		}
		System.out.println(c);

	}
}


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

public class and
{
	public static void main(String args[])throws IOException
	{
		BufferedReader BR=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(BR.readLine());
		int n=Integer.parseInt(st.nextToken());
		int x=Integer.parseInt(st.nextToken());

		StringTokenizer st1=new StringTokenizer(BR.readLine());

		ArrayList<Integer> arr=new ArrayList<Integer>();
		ArrayList<Integer> arr1=new ArrayList<Integer>();
		int c=-1;
		for(int i=0;i<n;i++)
		{
			int y=Integer.parseInt(st1.nextToken());
			if(arr.contains(y))
				{
					c=0;
					break;
				}
			arr.add(y);

			int j=y&x;

			if(arr.contains(j) && (arr.indexOf(j)!=i || arr.lastIndexOf(j)!=i))
			{
				c=1;
				break;
			}
			else if (arr1.contains(j))
			{
				c=2;
				break;
			}
			arr1.add(j);

		}
		System.out.println(c);

	}
}


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

public class and
{
	public static void main(String args[])throws IOException
	{
		BufferedReader BR=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(BR.readLine());
		int n=Integer.parseInt(st.nextToken());
		int x=Integer.parseInt(st.nextToken());

		StringTokenizer st1=new StringTokenizer(BR.readLine());

		ArrayList<Integer> arr=new ArrayList<Integer>();
		ArrayList<Integer> arr1=new ArrayList<Integer>();
		int c=Integer.MAX_VALUE;
		boolean b=true;
		for(int i=0;i<n;i++)
		{
			int y=Integer.parseInt(st1.nextToken());
			int j=y&x;

			if(arr.contains(y))
			{
					c=Math.min(c,0);
					b=false;
			}
			if (arr1.contains(y) || arr.contains(j))
			{
				c=Math.min(c,1);
				b=false;
			}

			if (arr1.contains(j))
			{
				c=Math.min(c,2);
				b=false;
			}

			arr.add(y);
			arr1.add(j);

		}
		if(b)
			System.out.println(-1);
		else
			System.out.println(c);

	}
}


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

public class and
{
	public static void main(String args[])throws IOException
	{
		BufferedReader BR=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(BR.readLine());
		int n=Integer.parseInt(st.nextToken());
		int x=Integer.parseInt(st.nextToken());

		StringTokenizer st1=new StringTokenizer(BR.readLine());

		ArrayList<Integer> arr=new ArrayList<Integer>();
		ArrayList<Integer> arr1=new ArrayList<Integer>();
		int c=-1;
		for(int i=0;i<n;i++)
		{
			int y=Integer.parseInt(st1.nextToken());
			if(arr.contains(y))
				{
					c=0;
					break;
				}

			int j=y&x;

			if(arr.contains(j))
			{
				c=1;
				break;
			}
			else if (arr1.contains(j))
			{
				c=2;
				break;
			}

			arr.add(y);
			arr1.add(j);

		}
		System.out.println(c);

	}
}


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

public class and
{
	public static void main(String args[])throws IOException
	{
		BufferedReader BR=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(BR.readLine());
		int n=Integer.parseInt(st.nextToken());
		int x=Integer.parseInt(st.nextToken());

		StringTokenizer st1=new StringTokenizer(BR.readLine());

		ArrayList<Integer> arr=new ArrayList<Integer>();
		ArrayList<Integer> arr1=new ArrayList<Integer>();
		int c=-1;
		for(int i=0;i<n;i++)
		{
			int y=Integer.parseInt(st1.nextToken());
			if(arr.contains(y))
				c=0;
			arr.add(y);

		}
		if(c==-1)
		{
			for(int i=0;i<n;i++)
			{
				int y=arr.get(i);
				int j=y&x;
				//System.out.println(j);
				if(arr.contains(j) && (arr.indexOf(j)!=i || arr.lastIndexOf(j)!=i))
				{
					c=1;
					break;
				}
				else if (arr1.contains(j))
					{
					c=2;
					break;
					}

				arr1.add(j);

			}
		}

		System.out.println(c);

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;

public class and
{
	public static void main(String args[])throws IOException
	{
		BufferedReader BR=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(BR.readLine());
		int n=Integer.parseInt(st.nextToken());
		int x=Integer.parseInt(st.nextToken());

		StringTokenizer st1=new StringTokenizer(BR.readLine());

		ArrayList<Integer> arr=new ArrayList<Integer>();
		ArrayList<Integer> arr1=new ArrayList<Integer>();

		HashMap<Integer,Integer> h=new HashMap<Integer,Integer>();
		HashMap<Integer,Integer> h1=new HashMap<Integer,Integer>();

		int c=Integer.MAX_VALUE;
		boolean b=true;
		for(int i=0;i<n;i++)
		{
			int y=Integer.parseInt(st1.nextToken());
			int j=y&x;

			if(h.containsKey(y))
			{
					c=Math.min(c,0);
					b=false;
					h.put(y,h.get(y)+1);
			}
			else
			{
				h.put(y,1);
			}
		}

		 Iterator it = h.entrySet().iterator();
		 while (it.hasNext())
		 {
			 Map.Entry pair = (Map.Entry)it.next();
			 int a=(int) pair.getKey();
			 int j=a&x;

			 if(h1.containsKey(j))
			 {
				h1.put(j,h1.get(j)+1);
				c=Math.min(c, 2);
				b=false;
			 }
			 else
			 {
				h1.put(j,1);
			 }

			 if(a==j)
			 {
				 continue;
			 }

			 if(h.containsKey(j))
			 {
				 c=Math.min(c,1);
				 b=false;
			 }
		 }

		if(b)
			System.out.println(-1);
		else
			System.out.println(c);

	}
}
class n
{
	int x=0;
	ArrayList<Integer> y=new ArrayList<Integer>();
}


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

public class Solution{

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String args[] ) {

        FastReader sc = new FastReader();

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n];
        int[] and = new int[n];
        int res=-1;

        for(int i=0;i<n;i++){
            arr[i] = sc.nextInt();
        }

        for(int i=0;i<n;i++){
            and[i] = arr[i]&k;
        }

        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(arr[i]==and[j] && i!=j){
                    res = 1;
                    break;
                }
            }
            if(res==1)
                break;
        }

        Arrays.sort(arr);
        for(int i=0;i<n-1;i++){
            if(arr[i]==arr[i+1]){
                res=0;
                break;
            }
        }

        if(res==-1){
            Arrays.sort(and);
            for(int i=0;i<n-1;i++){
                if(and[i]==and[i+1]){
                    res=2;
                    break;
                }
            }
        }

        System.out.println(res);

    }

}


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

public class Solution {

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String args[] ) {

        FastReader sc = new FastReader();

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n];
        int[] and = new int[n];
        int res=-1;
        HashMap<Integer,HashSet<Integer>> map = new HashMap<Integer,HashSet<Integer>>();

        for(int i=0;i<n;i++){
            arr[i] = sc.nextInt();
        }

        for(int i=0;i<n;i++){
            and[i] = arr[i]&k;

            if( map.containsKey(and[i]) ){
                HashSet<Integer> set = map.get(and[i]);
                set.add(i);
                map.put(and[i], set);
                res=2;
            }else{
                HashSet<Integer> set = new HashSet<Integer>();
                set.add(i);
                map.put(and[i], set);
            }
        }

        for(int i=0;i<n;i++){
            if(map.containsKey(arr[i]))
            {
                HashSet<Integer> set = map.get(arr[i]);
                if(!set.contains(i)||set.size()>1){
                    res=1;
                    break;
                }
            }
        }

        Arrays.sort(arr);
        for(int i=0;i<n-1;i++){
            if(arr[i]==arr[i+1]){
                res=0;
                break;
            }
        }

        System.out.println(res);

    }

}


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

public class Solution{

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String args[] ) {

        FastReader sc = new FastReader();

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n];
        int[] and = new int[n];
        int res=-1;

        for(int i=0;i<n;i++){
            arr[i] = sc.nextInt();
        }

        for(int i=0;i<n;i++){
            and[i] = arr[i]&k;
        }

        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(arr[i]==and[j]){
                    res = 1;
                    break;
                }
            }
            if(res==1)
                break;
        }

        Arrays.sort(arr);
        for(int i=0;i<n-1;i++){
            if(arr[i]==arr[i+1]){
                res=0;
                break;
            }
        }

        if(res==-1){
            Arrays.sort(and);
            for(int i=0;i<n-1;i++){
                if(and[i]==and[i+1]){
                    res=2;
                    break;
                }
            }
        }

        System.out.println(res);

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.util.*;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
public class B1013 {
    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

        public void printLine(int[] array) {
            print(array);
            writer.println();
        }

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

    }
    public static void main(String[] args) {
        //InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		//InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Scanner sc = new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //int n = in.readInt();
        int n = sc.nextInt();
        int k = sc.nextInt();
        //int[] temparr = IOUtils.readIntArray(in, n);
        int[] arr = new int[n];
        Map<Integer, Integer> map = new HashMap<>();
        Set<Integer> set = new HashSet<>();
        int flag = 0;
        for (int i=0; i<n; i++) {
            arr[i] = sc.nextInt();
            if (set.contains(arr[i])) {
                flag = 1;
                break;
            }
            set.add(arr[i]);
            map.put(arr[i], map.getOrDefault(arr[i],0)+1);
        }
        if (flag ==1 ) {
            System.out.println(0);
        } else {
            int ans = 0;
            set.clear();
            for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
                int x = entry.getKey();
                int p= x;
                x &= k;
                if (x != p) {
                    if (map.containsKey(x)) {
                        ans = 1;
                        break;
                    } else {
                        if (set.contains(x)) {
                            ans = 2;
                            break;
                        }
                        set.add(x);
                    }
                }
            }
            System.out.println(ans==0?-1:ans);
        }

        //out.printLine(rating);
        out.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.util.*;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
public class B1013 {
    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

        public void printLine(int[] array) {
            print(array);
            writer.println();
        }

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

    }
    public static void main(String[] args) {
        //InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		//InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Scanner sc = new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //int n = in.readInt();
        int n = sc.nextInt();
        int k = sc.nextInt();
        //int[] temparr = IOUtils.readIntArray(in, n);
        int[] arr = new int[n];
        Map<Integer, Integer> map = new HashMap<>();
        Map<Integer, Integer> map1 = new HashMap<>();
        Map<Integer, Integer> map2 = new HashMap<>();
        Map<Integer, Integer> map3 = new HashMap<>();
        Set<Integer> set = new HashSet<>();
        int flag = 0;
        for (int i=0; i<n; i++) {
            arr[i] = sc.nextInt();
            if (set.contains(arr[i])) {
                flag = 1;
                //break;
            }
            set.add(arr[i]);
            map.put(arr[i], i);
        }
        if (flag ==1 ) {
            System.out.println(0);
        } else {
            int ans = 0;
            set.clear();
            for (int i=0; i<n; i++) {
                arr[i] &= k;
                if (map.containsKey(arr[i]) && map.get(arr[i]) != i) {
                    //System.out.println("yo");
                    ans = 1;
                    break;
                }
                map1.put(arr[i], i);
            }
            if (ans == 1) {
                System.out.println(1);
            } else if (map1.size() != n) {
                System.out.println(2);
            } else {
                ans = Integer.MAX_VALUE;
                for (int i=0; i<n; i++) {
                    arr[i] &= k;
                    if (map.containsKey(arr[i]) && map.get(arr[i]) != i) {
                        ans = Math.min(ans, 2);
                        //break;
                    } else if (map1.containsKey(arr[i]) && map1.get(arr[i]) != i) {
                        ans = Math.min(ans, 3);
                    } else {
                        map2.put(arr[i], i);
                    }
                }
                if (ans != Integer.MAX_VALUE) {
                    System.out.println(ans);
                } else if (map2.size()!=n) {
                    System.out.println(4);
                }else {
                    for (int i=0; i<n; i++) {
                        arr[i] &= k;
                        if (map.containsKey(arr[i]) && map.get(arr[i]) != i) {
                            ans = Math.min(ans, 3);
                            //break;
                        } else if (map1.containsKey(arr[i]) && map1.get(arr[i]) != i) {
                            ans = Math.min(ans, 3);
                        } else if (map2.containsKey(arr[i]) && map2.get(arr[i]) != i) {
                            ans = Math.min(ans, 4);
                        } else {
                            map3.put(arr[i], 1);
                        }
                    }
                }
                if (map3.size() != n) {
                    System.out.println(Math.min(ans, 6));
                } else {
                    System.out.println(ans == Integer.MAX_VALUE ? -1 : ans);
                }

            }

        }

        //out.printLine(rating);
        out.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.util.*;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
public class B1013 {
    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

        public void printLine(int[] array) {
            print(array);
            writer.println();
        }

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

    }
    public static void main(String[] args) {
        //InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		//InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Scanner sc = new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //int n = in.readInt();
        int n = sc.nextInt();
        int k = sc.nextInt();
        //int[] temparr = IOUtils.readIntArray(in, n);
        int[] arr = new int[n];
        Map<Integer, Integer> map = new HashMap<>();
        Set<Integer> set = new HashSet<>();
        int flag = 0;
        for (int i=0; i<n; i++) {
            arr[i] = sc.nextInt();
            if (set.contains(arr[i])) {
                flag = 1;
                break;
            }
            set.add(arr[i]);
            map.put(arr[i], map.getOrDefault(arr[i],0)+1);
        }
        if (flag ==1 ) {
            System.out.println(0);
        } else {
            int ans = 0;
            set.clear();
            for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
                int x = entry.getKey();
                int p= x;
                x &= k;
                //if (x != p) {
                    if (map.containsKey(x) && p!=x) {
                        ans = 1;
                        break;
                    } else {
                        if (set.contains(x)) {
                            ans = 2;
                            break;
                        }
                        set.add(x);
                    }
                //}
            }
            System.out.println(ans==0?-1:ans);
        }

        //out.printLine(rating);
        out.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.util.*;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
public class B1013 {
    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

        public void printLine(int[] array) {
            print(array);
            writer.println();
        }

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

    }
    public static void main(String[] args) {
        //InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		//InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Scanner sc = new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //int n = in.readInt();
        int n = sc.nextInt();
        int k = sc.nextInt();
        //int[] temparr = IOUtils.readIntArray(in, n);
        int[] arr = new int[n];
        Map<Integer, Integer> map = new HashMap<>();
        Map<Integer, Integer> map1 = new HashMap<>();
        Set<Integer> set = new HashSet<>();
        int flag = 0;
        for (int i=0; i<n; i++) {
            arr[i] = sc.nextInt();
            if (set.contains(arr[i])) {
                flag = 1;
                break;
            }
            set.add(arr[i]);
            map.put(arr[i], map.getOrDefault(arr[i],0)+1);
        }
        if (flag ==1 ) {
            System.out.println(0);
        } else {
            int ans = 0;
            set.clear();
            for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
                int x = entry.getKey();
                int p= x;
                x &= k;
                //if (x != p) {
                    if (map.containsKey(x) && p!=x) {
                        ans = 1;
                        break;
                    } else {
                        map1.put(x, 1);
                    }
                //}
            }
            //System.out.println(ans==0?-1:ans);
            if (ans != 0) {
                System.out.println(ans);
            } else {
                for (Map.Entry<Integer, Integer> entry : map1.entrySet()) {
                    int x = entry.getKey();
                    int p= x;
                    x &= k;
                    //if (x != p) {
                        if (map.containsKey(x) && p!=x) {
                            ans = 2;
                            break;
                        } else if (map1.containsKey(x) && p!=x) {
                            ans = 3;
                            break;
                        }
                    //}
                }
                System.out.println(ans==0?-1:ans);
            }
        }

        //out.printLine(rating);
        out.close();
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        int bin;
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] == x) {
                a[i] = 0;
            }
            bin = a[i] & x;
            setx.add(bin);
            set.add(a[i]);
        }
        if (n != set.size()) {
            System.out.println(0);
        } else if (setx.contains(x) && set.contains(0)) {
            System.out.println(1);
        } else if (n != setx.size()) {
            System.out.println(2);
        } else {
            System.out.println(-1);
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Arrays.sort(a);
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(a[i]);
        }
        for (int i = 0; i < n - 1; i++) {
            if (a[i] == a[i + 1]) {
                System.out.println(0);
                return;
            }
        }
        for (int i = n - 1; i > 0; i--) {
            if ((a[i] & x) == (a[i - 1] & x)) {
                System.out.println(2);
                return;
            } else if (list.contains(x) && a[i] > x && (a[i] & x) == x) {
                System.out.println(1);
                return;
            }
        }
        System.out.println(-1);
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        int bin;
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] != x) {
                bin = a[i] & x;
                setx.add(bin);
                set.add(a[i]);
            } else {
                set.add(a[i]);
                a[i] = -1;
                setx.add(a[i]);
            }
        }
        if (n != set.size()) {
            System.out.println(0);
        } else if (setx.contains(x) && setx.contains(-1)) {
            System.out.println(1);
        } else if (n != setx.size()) {
            System.out.println(2);
        } else {
            System.out.println(-1);
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        int bin;
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] == x) {
                a[i] = -1;
            }
            bin = a[i] & x;
            setx.add(bin);
            set.add(a[i]);
        }
        if (n != set.size()) {
            System.out.println(0);
        } else if (setx.contains(x) && set.contains(-1)) {
            System.out.println(1);
        } else if (n != setx.size()) {
            System.out.println(2);
        } else {
            System.out.println(-1);
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            set.add(a[i]);
        }
        if (set.size() != n) {
            System.out.println(0);
            return;
        }
        for (int i = 0; i < n; i++) {
            if (set.contains(a[i] & x) && a[i] != (a[i] & x)) {
                System.out.println(1);
                return;
            } else if (setx.contains(a[i] & x)) {
                System.out.println(2);
                return;
            } else {
                setx.add(a[i] & x);
            }
        }
        System.out.println(-1);
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        int bin;
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] == x) {
                a[i] = -1;
            }
            bin = a[i] & x;
            setx.add(bin);
            set.add(a[i]);
        }
        if (n != set.size()) {
            System.out.println(0);
        } else if (n != setx.size() && set.contains(x) && setx.contains(x)) {
            System.out.println(1);
        } else if (n != setx.size()) {
            System.out.println(2);
        } else {
            System.out.println(-1);
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        int bin;
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] == x) {
                a[i] = 0;
            }
            bin = a[i] & x;
            setx.add(bin);
            set.add(a[i]);
        }
        if (n != set.size()) {
            System.out.println(0);
        } else if (setx.contains(x)) {
            System.out.println(1);
        } else if (n != setx.size()) {
            System.out.println(2);
        } else {
            System.out.println(-1);
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Arrays.sort(a);
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(a[i]);
        }
        for (int i = 0; i < n - 1; i++) {
            if (a[i] == a[i + 1]) {
                System.out.println(0);
                return;
            }
        }
        if (list.contains(x) && a[n - 1] > x) {
            System.out.println(1);
            return;
        }
        for (int i = n - 1; i > 0; i--) {
            if ((a[i] & x) == (a[i - 1] & x)) {
                System.out.println(2);
                return;
            } else if (list.contains(x) && a[i] > x && (a[i] & x) == x) {
                System.out.println(1);
                return;
            }
        }
        System.out.println(-1);
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        boolean f = false;
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            set.add(a[i]);
        }
        if (set.size() != n) {
            System.out.println(0);
            return;
        }
        for (int i = 0; i < n; i++) {
            if (set.contains(a[i] & x) && a[i] != (a[i] & x)) {
                System.out.println(1);
                return;
            } else if (setx.contains(a[i] & x)) {
                f = true;
            } else {
                setx.add(a[i] & x);
            }
        }
        if (f) {
            System.out.println(2);
        } else {
            System.out.println(-1);
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Arrays.sort(a);
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(a[i]);
        }
        for (int i = 0; i < n - 1; i++) {
            if (a[i] == a[i + 1]) {
                System.out.println(0);
                return;
            }
        }
        if (list.contains(x) && a[n - 1] > x) {
            System.out.println(1);
            return;
        }
        for (int i = 0; i < n; i++) {
            if (list.contains(a[i] & x) && a[i] != (a[i] & x)) {
                System.out.println(1);
                return;
            } else {
                System.out.println(-1);
                return;
            }
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Arrays.sort(a);
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(a[i]);
        }
        for (int i = 0; i < n - 1; i++) {
            if (a[i] == a[i + 1]) {
                System.out.println(0);
                return;
            }
        }
        for (int i = n - 1; i > 0; i--) {
            if ((a[i] & x) == (a[i - 1] & x) && !list.contains(x)) {
                System.out.println(2);
                return;
            } else if (list.contains(x) && a[i] > x && (a[i] & x) == x) {
                System.out.println(1);
                return;
            }
        }
        System.out.println(-1);
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        int bin;
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] == x) {
                a[i] = 0;
            }
            bin = a[i] & x;
            setx.add(bin);
            set.add(a[i]);
        }
        if (n != set.size()) {
            System.out.println(0);
        } else if (n != setx.size() && setx.contains(x)) {
            System.out.println(1);
        } else if (n != setx.size()) {
            System.out.println(2);
        } else {
            System.out.println(-1);
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        int bin;
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            bin = a[i] & x;
            setx.add(bin);
            set.add(a[i]);
        }
        if (n != set.size()) {
            System.out.println(0);
        } else if (n != setx.size() && set.contains(x) && setx.contains(x)) {
            System.out.println(1);
        } else if (n != setx.size()) {
            System.out.println(2);
        } else {
            System.out.println(-1);
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            set.add(a[i]);
        }
        if (set.size() != n) {
            System.out.println(0);
            return;
        }
        for (int i = 0; i < n; i++) {
            if (set.contains(a[i] & x) && a[i] != (a[i] & x)) {
                System.out.println(1);
                return;
            } else if (setx.contains(a[i] & x)) {
                System.out.println(2);
                return;
            } else {
                setx.add(a[i]);
            }
        }
        System.out.println(-1);
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        int bin;
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] != x) {
                bin = a[i] & x;
                setx.add(bin);
                set.add(a[i]);
            } else {
                set.add(a[i]);
                a[i] = -1;
                setx.add(a[i]);
            }
        }
        if (n != set.size()) {
            System.out.println(0);
        } else if (setx.contains(-1) && set.contains(x)) {
            System.out.println(1);
        } else if (n != setx.size()) {
            System.out.println(2);
        } else {
            System.out.println(-1);
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        int bin;
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (a[i] == x) {
                a[i] = 0;
            }
            bin = a[i] & x;
            setx.add(bin);
            set.add(a[i]);
        }
        if (n != set.size()) {
            System.out.println(0);
        } else if (setx.contains(x) && set.contains(0)) {
            System.out.println(1);
        } else if (n != setx.size() && !set.contains(0)) {
            System.out.println(2);
        } else {
            System.out.println(-1);
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Arrays.sort(a);
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(a[i]);
        }
        for (int i = 0; i < n - 1; i++) {
            if (a[i] == a[i + 1]) {
                System.out.println(0);
                return;
            }
        }
        if (list.contains(x) && a[n - 1] > x) {
            System.out.println(1);
            return;
        } else if (a[n - 1] > x && a[n - 2] > x) {
            System.out.println(2);
            return;
        }
        System.out.println(-1);
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        int bin;
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            bin = a[i] & x;
            setx.add(bin);
            set.add(a[i]);
        }
        if (n != set.size()) {
            System.out.println(0);
        } else if (n - setx.size() == 1) {
            System.out.println(1);
        } else if (n - setx.size() == 2) {
            System.out.println(2);
        } else {
            System.out.println(-1);
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        int bin;
        Set<Integer> set = new TreeSet<>();
        Set<Integer> setx = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            bin = a[i] & x;
            setx.add(bin);
            set.add(a[i]);
        }
        if (n != set.size()) {
            System.out.println(0);
        } else if (n != setx.size() && set.contains(x)) {
            System.out.println(1);
        } else if (n != setx.size()) {
            System.out.println(2);
        } else {
            System.out.println(-1);
        }
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Arrays.sort(a);
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(a[i]);
        }
        for (int i = 0; i < n - 1; i++) {
            if (a[i] == a[i + 1]) {
                System.out.println(0);
                return;
            }
        }
        if (list.contains(x) && a[n - 1] > x) {
            System.out.println(1);
            return;
        }
        for (int i = n - 1; i > 0; i--) {
            if ((a[i] & x) == (a[i - 1] & x)) {
                System.out.println(2);
                return;
            }
        }
        System.out.println(-1);
    }
}


import java.util.*;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Arrays.sort(a);
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(a[i]);
        }
        for (int i = 0; i < n - 1; i++) {
            if (a[i] == a[i + 1]) {
                System.out.println(0);
                return;
            }
        }
        if (list.contains(x) && a[n - 1] > x) {
            System.out.println(1);
            return;
        }
        for (int i = n - 1; i < 0; i++) {
            if ((a[i - 1] & x) == (a[i - 2] & x)) {
                System.out.println(2);
            }
        }
        System.out.println(-1);
    }
}


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

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int x = in.nextInt();
            int arr[] = new int[n];
            int flag = 0;
            HashSet<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
                if (set.contains(arr[i])) flag = 1;
                set.add(arr[i]);
            }
            if (flag == 1) {
                out.println(0);
                return;
            }
            int b[] = new int[n];
            for (int i = 0; i < n; i++) {
                b[i] = arr[i] & x;
            }
            Arrays.sort(b);
            int flagx = 0;
            if (set.contains(x)) flagx = 1;
            int flag2 = 0;
            for (int i = 1; i < n; i++) {
                if (b[i - 1] == b[i]) flag2 = 1;
            }
            if (flag2 == 1 && flagx == 1) out.println(1);
            else if (flag2 == 1 && flagx == 0) out.println(2);
            else out.println(-1);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }
}


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

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int x = in.nextInt();
            int arr[] = new int[n];
            int flag = 0;
            HashSet<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
                if (set.contains(arr[i])) flag = 1;
                set.add(arr[i]);
            }
            if (flag == 1) {
                out.println(0);
                return;
            }
            int b[] = new int[n];
            for (int i = 0; i < n; i++) {
                b[i] = arr[i] & x;
            }
            Arrays.sort(b);
            int flagx = 0;
            int flag2 = 0;
            for (int i = 1; i < n; i++) {
                if (b[i - 1] == b[i]) {
                    if (set.contains(b[i])) flagx = 1;
                    flag2 = 1;
                }
            }
            if (flag2 == 1 && flagx == 1) out.println(1);
            else if (flag2 == 1 && flagx == 0) out.println(2);
            else out.println(-1);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }
}


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

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int x = in.nextInt();
            int arr[] = new int[n];
            int flag = 0;
            HashSet<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
                if (set.contains(arr[i])) flag = 1;
                set.add(arr[i]);
            }
            if (flag == 1) {
                out.println(0);
                return;
            }
            int b[] = new int[n];
            for (int i = 0; i < n; i++) {
                b[i] = arr[i] & x;
            }
            Arrays.sort(b);
            int flag2 = 0;
            for (int i = 1; i < n; i++) {
                if (b[i - 1] == b[i]) flag2 = 1;
            }
            if (flag2 == 1) out.println(1);
            else out.println(-1);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }
}


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

public class Solution
{
    static class InputReader
    {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

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

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

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

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

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

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

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

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

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

    public static void main(String[] args)throws Exception
    {
        InputReader in=new InputReader(System.in);
        PrintWriter w=new PrintWriter(System.out);
        int n=in.nextInt();
        int x=in.nextInt();
        int[] ar=new int[n];
        ar=in.nextIntArray(n);
        int[] fr=new int[100001];
        for(int i=0;i<n;i++)
        {
            fr[ar[i]]++;
        }
        boolean pos=false;
        Arrays.sort(ar);
        for(int i=0;i<n;i++)
        {
            if(fr[ar[i]]==2)
            {
                pos=true;
                break;
            }
        }
        if(!pos)
        {
            int min=Integer.MAX_VALUE;
            int[] count=new int[100001];
            for(int i=n-1;i>=0;i--)
            {
                if((fr[ar[i]&x]>=1) && (ar[i]&x)!=ar[i])
                {
                    count[ar[i]&x]++;
                    if(count[ar[i]&x]<min)
                        min=count[ar[i]&x];
                    pos=true;
                }
                else
                {
                    fr[ar[i]]--;
                    ar[i]=ar[i]&x;
                    fr[ar[i]]++;
                    count[ar[i]]++;
                }
            }
            if(pos)
            {
                w.println(min);
            }
            else
            {
                w.println("-1");
            }
        }
        else
        {
            w.println("0");
        }
        w.close();
    }
}


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

public class Solution
{
    static class InputReader
    {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

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

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

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

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

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

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

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

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

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

    public static void main(String[] args)throws Exception
    {
        InputReader in=new InputReader(System.in);
        PrintWriter w=new PrintWriter(System.out);
        int n=in.nextInt();
        int x=in.nextInt();
        int[] ar=new int[n];
        ar=in.nextIntArray(n);
        int[] fr=new int[100001];
        for(int i=0;i<n;i++)
        {
            fr[ar[i]]++;
        }
        boolean pos=false;
        Arrays.sort(ar);
        for(int i=0;i<n;i++)
        {
            if(fr[i]==2)
            {
                pos=true;
                break;
            }
        }
        if(!pos)
        {
            int min=Integer.MAX_VALUE;
            int[] count=new int[100001];
            for(int i=n-1;i>=0;i--)
            {
                if((fr[ar[i]&x]>=1) && (ar[i]&x)!=ar[i])
                {
                    count[ar[i]&x]++;
                    if(count[ar[i]&x]<min)
                        min=count[ar[i]&x];
                    pos=true;
                }
                else
                {
                    fr[ar[i]]--;
                    ar[i]=ar[i]&x;
                    fr[ar[i]]++;
                    count[ar[i]]++;
                }
            }
            if(pos)
            {
                w.println(min);
            }
            else
            {
                w.println("-1");
            }
        }
        else
        {
            w.println("0");
        }
        w.close();
    }
}


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

public class Solution
{
    static class InputReader
    {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

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

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

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

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

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

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

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

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

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

    public static void main(String[] args)throws Exception
    {
        InputReader in=new InputReader(System.in);
        PrintWriter w=new PrintWriter(System.out);
        int n=in.nextInt();
        int x=in.nextInt();
        int[] ar=new int[n];
        ar=in.nextIntArray(n);
        int[] fr=new int[100001];
        for(int i=0;i<n;i++)
        {
            fr[ar[i]]++;
        }
        boolean pos=false;
        Arrays.sort(ar);
        for(int i=0;i<n;i++)
        {
            if(fr[ar[i]]>=2)
            {
                pos=true;
                break;
            }
        }
        if(!pos)
        {
            int min=Integer.MAX_VALUE;
            int[] count=new int[100001];
            for(int i=n-1;i>=0;i--)
            {
                if((fr[ar[i]&x]>=1) && (ar[i]&x)!=ar[i])
                {
                    count[ar[i]&x]++;
                    if(count[ar[i]&x]<min)
                        min=count[ar[i]&x];
                    pos=true;
                }
                else
                {
                    fr[ar[i]]--;
                    ar[i]=ar[i]&x;
                    fr[ar[i]]++;
                    count[ar[i]]++;
                }
            }
            if(pos)
            {
                w.println(min);
            }
            else
            {
                w.println("-1");
            }
        }
        else
        {
            w.println("0");
        }
        w.close();
    }
}