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

public class And {
    public static void main(String[] args) {
       FastReader input = new FastReader();
        OutputStream ob = System.out;
        PrintWriter out = new PrintWriter(ob);
        int n = input.nextInt();
        int k = input.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        for(int i = 0;i < n;i++){
            int num = input.nextInt();
            list.add(num);
        }
        ArrayList<Integer> list2 = new ArrayList<Integer>();
        Collections.sort(list);
        for(int i = 0;i < list.size();i++){
            if(i < n-1){
                if(list.get(i) == list.get(i+1)){
                    out.print(0);
                    out.flush();
                    return;
                }
            }
        }

        for(int i = 0;i < n;i++){
            int val = list.get(i) & k;
            for(int j = 0;j < n;j++){
                if(j != i){
                    if(list.get(j) == val){
                        out.print(1);
                        out.flush();
                        return;
                    }
                }
            }
            if(list2.contains(val)){
                out.print(2);
                out.flush();
                return;
            }
            list2.add(val);
        }
        out.print(-1);
        out.flush();

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


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

public class And {
    public static void main(String[] args) {
       FastReader input = new FastReader();
        OutputStream ob = System.out;
        PrintWriter out = new PrintWriter(ob);
        int n = input.nextInt();
        int x = input.nextInt();
        int[] arr = new int[n];
        int[] count = new int[2000000];
        int[] count2 = new int[2000000];
        int[] arr2 = new int[n];
        for(int i = 0;i < n;i++){
            arr[i] = input.nextInt();
            count[arr[i]]++;
            if(count[arr[i]] > 1){
                out.print(0);
                out.flush();
                return;
            }
            int val = arr[i] & x;
            arr2[i] = val;
            count2[val]++;
        }
        Arrays.sort(arr);
//        for(int i : arr2){
//            System.out.print(i + " ");
//        }
//        System.out.println();
        for(int i = 0;i < n;i++){
            if(i == 0){
                int a = Arrays.binarySearch(arr,1,arr.length,arr2[i]);
                if(a >= 0){
                    out.print(1);
                    out.flush();
                    return;
                }
            }
            else if(i == n-1){
                int b = Arrays.binarySearch(arr,0,n-1,arr2[i]);
              //  System.out.println("b = " + b + " arr2[i] = " + arr2[i]);
                if(b >= 0){
                    out.print(1);
                    out.flush();
                    return;
                }
            }
            else{
                int c = Arrays.binarySearch(arr,0,i,arr2[i]);
                int d = Arrays.binarySearch(arr,i+1,n,arr2[i]);
                if(c >= 0 || d >= 0){
                    out.print(1);
                    out.flush();
                    return;
                }
            }
        }
        for(int i : count2){
            if(i > 1){
                out.print(2);
                out.flush();
                return;
            }
        }
        out.print(-1);
        out.flush();
    }
    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;
        }
    }
}


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

public class And {
    public static void main(String[] args) {
       FastReader input = new FastReader();
        OutputStream ob = System.out;
        PrintWriter out = new PrintWriter(ob);
        int n = input.nextInt();
        int x = input.nextInt();
        int[] arr = new int[n];
        int[] count = new int[2000000];
        int[] count2 = new int[2000000];
        int[] arr2 = new int[n];
        for(int i = 0;i < n;i++){
            arr[i] = input.nextInt();
            count[arr[i]]++;
            if(count[arr[i]] > 1){
                out.print(0);
                out.flush();
                return;
            }
            int val = arr[i] & x;
            arr2[i] = val;
            count2[val]++;
        }
        Arrays.sort(arr);
        for(int i= 0;i < n;i++){
            int index = Arrays.binarySearch(arr,arr2[i]);
            if(index >= 0 && index != i){
                out.print(1);
                out.flush();
                return;
            }
        }
        for(int i : count2){
            if(i > 1){
                out.print(2);
                out.flush();
                return;
            }
        }
        out.print(-1);
        out.flush();
    }
    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;
        }
    }
}


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

public class And {
    public static void main(String[] args) {
        FastReader input = new FastReader();
        OutputStream ob = System.out;
        PrintWriter out = new PrintWriter(ob);
        int n = input.nextInt();
        int x = input.nextInt();
        int[] arr = new int[n];
        int[] count = new int[2000000];
        int[] count2 = new int[2000000];
        for(int i = 0;i < n;i++){
            arr[i] = input.nextInt();
            count[arr[i]]++;
            if(count[arr[i]] > 1) {
                out.print(0);
                out.flush();
                return;
            }
            int val = arr[i] & x;
            count2[val]++;
        }
       for(int i = 0;i < n;i++){
            int val = arr[i] & x;
            if(val == arr[i] && count[val] > 1){
                out.print(1);
                out.flush();
                return;
            }
            else if(val != arr[i] && count[val] > 0){
                out.print(1);
                out.flush();
                return;
            }
       }

        for(int i : count2){
            if(i > 1){
                out.print(2);
                out.flush();
                return;
            }
        }
        out.print(-1);
        out.flush();
    }
    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;
        }
    }
}


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

public class And {
    public static void main(String[] args) {
        FastReader input = new FastReader();
        OutputStream ob = System.out;
        PrintWriter out = new PrintWriter(ob);
        int n = input.nextInt();
        int x = input.nextInt();
        int[] arr = new int[n];
        int[] count = new int[2000000];
        int[] count2 = new int[2000000];
        int[] arr2 = new int[n];
        for(int i = 0;i < n;i++){
            arr[i] = input.nextInt();
            count[arr[i]]++;
            if(count[arr[i]] > 1){
                out.print(0);
                out.flush();
                return;
            }
            int val = arr[i] & x;
            arr2[i] = val;
            count2[val]++;
        }

        for(int i = 0;i < n;i++){
            if(i == 0){
                int[] temparr = Arrays.copyOfRange(arr,1,n);
                Arrays.sort(temparr);
                int a = Arrays.binarySearch(temparr,arr2[i]);
                if(a >= 0){
                    out.print(1);
                    out.flush();
                    return;
                }
            }
            else if(i == n-1){
                int[] temparr2 = Arrays.copyOfRange(arr,0,n-1);
                Arrays.sort(temparr2);
                int b = Arrays.binarySearch(temparr2,arr2[i]);
                //  System.out.println("b = " + b + " arr2[i] = " + arr2[i]);
                if(b >= 0){
                    out.print(1);
                    out.flush();
                    return;
                }
            }
            else{
                int[] temparr3 = Arrays.copyOfRange(arr,0,i);
                Arrays.sort(temparr3);
                int[] temparr4 = Arrays.copyOfRange(arr,i+1,n);
                Arrays.sort(temparr4);
                int c = Arrays.binarySearch(temparr3,arr2[i]);
                int d = Arrays.binarySearch(temparr4,arr2[i]);
                if(c >= 0 || d >= 0){
                    out.print(1);
                    out.flush();
                    return;
                }
            }
        }
        for(int i : count2){
            if(i > 1){
                out.print(2);
                out.flush();
                return;
            }
        }
        out.print(-1);
        out.flush();
    }
    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;
        }
    }
}


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

public class And {
    public static void main(String[] args) {
       FastReader input = new FastReader();
        OutputStream ob = System.out;
        PrintWriter out = new PrintWriter(ob);
        int n = input.nextInt();
        int k = input.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        for(int i = 0;i < n;i++){
            int num = input.nextInt();
            list.add(num);
        }
        ArrayList<Integer> list2 = new ArrayList<Integer>();
        for(int i : list){
            int fq = Collections.frequency(list,i);
            if(fq > 1){
                out.print(0);
                out.flush();
                return;
            }
        }

        for(int i = 0;i < n;i++){
            int val = list.get(i) & k;
            for(int j = 0;j < n;j++){
                if(j != i){
                    if(list.get(j) == val){
                        out.print(1);
                        out.flush();
                        return;
                    }
                }
            }
            if(list2.contains(val)){
                out.print(2);
                out.flush();
                return;
            }
            list2.add(val);
        }
        out.print(-1);
        out.flush();

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


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

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

public class a{
     static int[] count,count1,count2;
     static Node[] nodes;
     static int[] arr;
     static int[] dp;
     static char[] ch,ch1;
     static int[] darr,farr;
     static Character[][] mat,mat1;
     static long x,h;
     static long maxl;
     static double dec;
     static String s;
     static long minl;
     static int mx = (int)1e9+5;
     static long mod = 998244353l;
     // static int minl = -1;
     // static long n;
     static int n,n1,n2;
     static long a;
     static long b;
     static long c;
     static long d;
     static long y,z;
     static int m;
     static long k;
     static String[] str,str1;
     static Set<Long> set,set1,set2;
     static List<Long> list,list1,list2,list3;
     static LinkedList<Node> ll;
     static Map<String,String> map;
     static StringBuilder sb,sb1,sb2;
     static int[] dx = {0,-1,0,1};
     static int[] dy = {-1,0,1,0};

     // public static void solve(){

     //    FastScanner sc = new FastScanner();

     //    int n = sc.nextInt();
     //    long m = sc.nextLong();

     //    list  = new ArrayList<>();
     //    long sum = 0;
     //    for(int i = 0 ; i < n ; i++){

     //        long a = sc.nextLong();
     //        long b = sc.nextLong();

     //        list.add(a-b);
     //        sum += a;

     //    }

     //    if(sum <= m){
     //        System.out.println("0");
     //        return;
     //    }

     //    Collections.sort(list);

     //    for(int i = n-1 ; i > -1 ; i--){
     //        sum -= list.get(i);
     //        if(sum <= m){
     //            System.out.println(n-i);
     //            return;
     //        }
     //    }

     //    System.out.println("-1");

     // }

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

     public static void solve(){

        count = new int[100005];
        count1 = new int[100005];
        for(int i = 0 ; i < n ; i++){
            count[arr[i]] += 1;
            if(count[arr[i]] == 2){
                System.out.println("0");
                return;
            }
        }

        for(int i = 0 ; i < n; i++){

            count1[arr[i]&m] += 1;

            if((count[arr[i]&m] > 1)){
                System.out.println("1");
                return;
            }

            if((count1[arr[i]&m] == 2)){
                System.out.println("2");
                return;
            }

        }

        System.out.println("-1");

     }

     public static void main(String[] args) {

            FastScanner sc = new FastScanner();
            // Scanner sc = new Scanner(System.in);
            // int t = sc.nextInt();
            int t = 1;
            // int l = 1;
            while(t > 0){

                // n = sc.nextInt();
                // n = sc.nextLong();
                // a = sc.nextLong();
                // b = sc.nextLong();
                // c = sc.nextLong();
                // d = sc.nextLong();

                // x = sc.nextLong();
                // y = sc.nextLong();

                // n = sc.nextLong();
                n = sc.nextInt();
                // n1 = sc.nextInt();

                m = sc.nextInt();

                // k = sc.nextLong();
                // s = sc.next();

                // ch = sc.next().toCharArray();
                // ch1 = sc.next().toCharArray();

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

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

                // mat = new Character[n][n];
                // for(int i = 0 ; i < n ; i++){
                //     String s = sc.next();
                //     for(int j = 0 ; j < n ; j++){
                //         mat[i][j] = s.charAt(j);
                //     }
                // }
                // str = new String[n];
                // for(int i = 0 ; i < n ; i++)
                //     str[i] = sc.next();

                // nodes = new Node[n];
                // for(int i = 0 ; i < n ;i++)
                //     nodes[i] = new Node(sc.nextInt(),sc.nextInt());

                // System.out.println(solve()?"YES":"NO");
                 solve();
                 // System.out.println(solve());
                 t -= 1;
            }

     }

    public static int log(long n){

         if(n == 0 || n == 1)
             return 0;

         if(n == 2)
             return 1;

         double num = Math.log(n);
         double den = Math.log(2);

         if(den == 0)
             return 0;

         return (int)(num/den);
     }

    public static boolean isPrime(long n) {
    // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
    }

     public static long gcd(long a,long b){

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

     }

     // public static void swap(int i,int j){
     //     long temp = arr[j];
     //     arr[j] = arr[i];
     //     arr[i] = temp;
     // }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class Node{
        int first;
        int second;
        Node(int f,int s){
            this.first = f;
            this.second = s;
        }
    }

     static class FastScanner {

                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st=new StringTokenizer("");
                String next() {
                        while (!st.hasMoreTokens())
                                try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        return st.nextToken();
                }

                int nextInt() {
                        return Integer.parseInt(next());
                }
                int[] readArray(int n) {
                        int[] a=new int[n];
                        for (int i=0; i<n; i++) a[i]=nextInt();
                        return a;
                }
                long nextLong() {
                        return Long.parseLong(next());
                }
        }

}


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

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

public class a{
     static int[] count,count1,count2;
     static Node[] nodes;
     static int[] arr;
     static int[] dp;
     static char[] ch,ch1;
     static int[] darr,farr;
     static Character[][] mat,mat1;
     static long x,h;
     static long maxl;
     static double dec;
     static String s;
     static long minl;
     static int mx = (int)1e9+5;
     static long mod = 998244353l;
     // static int minl = -1;
     // static long n;
     static int n,n1,n2;
     static long a;
     static long b;
     static long c;
     static long d;
     static long y,z;
     static int m;
     static long k;
     static String[] str,str1;
     static Set<Long> set,set1,set2;
     static List<Long> list,list1,list2,list3;
     static LinkedList<Node> ll;
     static Map<String,String> map;
     static StringBuilder sb,sb1,sb2;
     static int[] dx = {0,-1,0,1};
     static int[] dy = {-1,0,1,0};

     // public static void solve(){

     //    FastScanner sc = new FastScanner();

     //    int n = sc.nextInt();
     //    long m = sc.nextLong();

     //    list  = new ArrayList<>();
     //    long sum = 0;
     //    for(int i = 0 ; i < n ; i++){

     //        long a = sc.nextLong();
     //        long b = sc.nextLong();

     //        list.add(a-b);
     //        sum += a;

     //    }

     //    if(sum <= m){
     //        System.out.println("0");
     //        return;
     //    }

     //    Collections.sort(list);

     //    for(int i = n-1 ; i > -1 ; i--){
     //        sum -= list.get(i);
     //        if(sum <= m){
     //            System.out.println(n-i);
     //            return;
     //        }
     //    }

     //    System.out.println("-1");

     // }

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

     public static void solve(){

        count = new int[100005];
        count1 = new int[100005];
        for(int i = 0 ; i < n ; i++){
            count[arr[i]] += 1;
            if(count[arr[i]] == 2){
                System.out.println("0");
                return;
            }
        }

        for(int i = 0 ; i < n; i++){

            count1[arr[i]&m] += 1;

            if((count[arr[i]%m] > 1)){
                System.out.println("1");
                return;
            }

            if((count1[arr[i]&m] == 2)){
                System.out.println("2");
                return;
            }

        }

        System.out.println("-1");

     }

     public static void main(String[] args) {

            FastScanner sc = new FastScanner();
            // Scanner sc = new Scanner(System.in);
            // int t = sc.nextInt();
            int t = 1;
            // int l = 1;
            while(t > 0){

                // n = sc.nextInt();
                // n = sc.nextLong();
                // a = sc.nextLong();
                // b = sc.nextLong();
                // c = sc.nextLong();
                // d = sc.nextLong();

                // x = sc.nextLong();
                // y = sc.nextLong();

                // n = sc.nextLong();
                n = sc.nextInt();
                // n1 = sc.nextInt();

                m = sc.nextInt();

                // k = sc.nextLong();
                // s = sc.next();

                // ch = sc.next().toCharArray();
                // ch1 = sc.next().toCharArray();

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

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

                // mat = new Character[n][n];
                // for(int i = 0 ; i < n ; i++){
                //     String s = sc.next();
                //     for(int j = 0 ; j < n ; j++){
                //         mat[i][j] = s.charAt(j);
                //     }
                // }
                // str = new String[n];
                // for(int i = 0 ; i < n ; i++)
                //     str[i] = sc.next();

                // nodes = new Node[n];
                // for(int i = 0 ; i < n ;i++)
                //     nodes[i] = new Node(sc.nextInt(),sc.nextInt());

                // System.out.println(solve()?"YES":"NO");
                 solve();
                 // System.out.println(solve());
                 t -= 1;
            }

     }

    public static int log(long n){

         if(n == 0 || n == 1)
             return 0;

         if(n == 2)
             return 1;

         double num = Math.log(n);
         double den = Math.log(2);

         if(den == 0)
             return 0;

         return (int)(num/den);
     }

    public static boolean isPrime(long n) {
    // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
    }

     public static long gcd(long a,long b){

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

     }

     // public static void swap(int i,int j){
     //     long temp = arr[j];
     //     arr[j] = arr[i];
     //     arr[i] = temp;
     // }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class Node{
        int first;
        int second;
        Node(int f,int s){
            this.first = f;
            this.second = s;
        }
    }

     static class FastScanner {

                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st=new StringTokenizer("");
                String next() {
                        while (!st.hasMoreTokens())
                                try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        return st.nextToken();
                }

                int nextInt() {
                        return Integer.parseInt(next());
                }
                int[] readArray(int n) {
                        int[] a=new int[n];
                        for (int i=0; i<n; i++) a[i]=nextInt();
                        return a;
                }
                long nextLong() {
                        return Long.parseLong(next());
                }
        }

}


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

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

public class a{
     static int[] count,count1,count2;
     static Node[] nodes;
     static int[] arr;
     static int[] dp;
     static char[] ch,ch1;
     static int[] darr,farr;
     static Character[][] mat,mat1;
     static long x,h;
     static long maxl;
     static double dec;
     static String s;
     static long minl;
     static int mx = (int)1e9+5;
     static long mod = 998244353l;
     // static int minl = -1;
     // static long n;
     static int n,n1,n2;
     static long a;
     static long b;
     static long c;
     static long d;
     static long y,z;
     static int m;
     static long k;
     static String[] str,str1;
     static Set<Long> set,set1,set2;
     static List<Long> list,list1,list2,list3;
     static LinkedList<Node> ll;
     static Map<String,String> map;
     static StringBuilder sb,sb1,sb2;
     static int[] dx = {0,-1,0,1};
     static int[] dy = {-1,0,1,0};

     // public static void solve(){

     //    FastScanner sc = new FastScanner();

     //    int n = sc.nextInt();
     //    long m = sc.nextLong();

     //    list  = new ArrayList<>();
     //    long sum = 0;
     //    for(int i = 0 ; i < n ; i++){

     //        long a = sc.nextLong();
     //        long b = sc.nextLong();

     //        list.add(a-b);
     //        sum += a;

     //    }

     //    if(sum <= m){
     //        System.out.println("0");
     //        return;
     //    }

     //    Collections.sort(list);

     //    for(int i = n-1 ; i > -1 ; i--){
     //        sum -= list.get(i);
     //        if(sum <= m){
     //            System.out.println(n-i);
     //            return;
     //        }
     //    }

     //    System.out.println("-1");

     // }

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

     public static void solve(){

        count = new int[100005];
        count1 = new int[100005];
        for(int i = 0 ; i < n ; i++){
            count[arr[i]] += 1;
            if(count[arr[i]] == 2){
                System.out.println("0");
                return;
            }
        }

        int minl = -1;
        for(int i = 0 ; i < n; i++){

            count1[arr[i]&m] += 1;

            if(((count[arr[i]&m] == 1) && ((arr[i]&m) != arr[i]))){
                System.out.println("1");
                return;
            }

            if((count1[arr[i]&m] == 2)){
                minl = 2;
            }

        }

        System.out.println(minl);

     }

     public static void main(String[] args) {

            FastScanner sc = new FastScanner();
            // Scanner sc = new Scanner(System.in);
            // int t = sc.nextInt();
            int t = 1;
            // int l = 1;
            while(t > 0){

                // n = sc.nextInt();
                // n = sc.nextLong();
                // a = sc.nextLong();
                // b = sc.nextLong();
                // c = sc.nextLong();
                // d = sc.nextLong();

                // x = sc.nextLong();
                // y = sc.nextLong();

                // n = sc.nextLong();
                n = sc.nextInt();
                // n1 = sc.nextInt();

                m = sc.nextInt();

                // k = sc.nextLong();
                // s = sc.next();

                // ch = sc.next().toCharArray();
                // ch1 = sc.next().toCharArray();

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

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

                // mat = new Character[n][n];
                // for(int i = 0 ; i < n ; i++){
                //     String s = sc.next();
                //     for(int j = 0 ; j < n ; j++){
                //         mat[i][j] = s.charAt(j);
                //     }
                // }
                // str = new String[n];
                // for(int i = 0 ; i < n ; i++)
                //     str[i] = sc.next();

                // nodes = new Node[n];
                // for(int i = 0 ; i < n ;i++)
                //     nodes[i] = new Node(sc.nextInt(),sc.nextInt());

                // System.out.println(solve()?"YES":"NO");
                 solve();
                 // System.out.println(solve());
                 t -= 1;
            }

     }

    public static int log(long n){

         if(n == 0 || n == 1)
             return 0;

         if(n == 2)
             return 1;

         double num = Math.log(n);
         double den = Math.log(2);

         if(den == 0)
             return 0;

         return (int)(num/den);
     }

    public static boolean isPrime(long n) {
    // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
    }

     public static long gcd(long a,long b){

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

     }

     // public static void swap(int i,int j){
     //     long temp = arr[j];
     //     arr[j] = arr[i];
     //     arr[i] = temp;
     // }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class Node{
        int first;
        int second;
        Node(int f,int s){
            this.first = f;
            this.second = s;
        }
    }

     static class FastScanner {

                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st=new StringTokenizer("");
                String next() {
                        while (!st.hasMoreTokens())
                                try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        return st.nextToken();
                }

                int nextInt() {
                        return Integer.parseInt(next());
                }
                int[] readArray(int n) {
                        int[] a=new int[n];
                        for (int i=0; i<n; i++) a[i]=nextInt();
                        return a;
                }
                long nextLong() {
                        return Long.parseLong(next());
                }
        }

}


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

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

public class a{
     static int[] count,count1,count2;
     static Node[] nodes;
     static int[] arr;
     static int[] dp;
     static char[] ch,ch1;
     static int[] darr,farr;
     static Character[][] mat,mat1;
     static long x,h;
     static long maxl;
     static double dec;
     static String s;
     static long minl;
     static int mx = (int)1e9+5;
     static long mod = 998244353l;
     // static int minl = -1;
     // static long n;
     static int n,n1,n2;
     static long a;
     static long b;
     static long c;
     static long d;
     static long y,z;
     static int m;
     static long k;
     static String[] str,str1;
     static Set<Long> set,set1,set2;
     static List<Long> list,list1,list2,list3;
     static LinkedList<Node> ll;
     static Map<String,String> map;
     static StringBuilder sb,sb1,sb2;
     static int[] dx = {0,-1,0,1};
     static int[] dy = {-1,0,1,0};

     // public static void solve(){

     //    FastScanner sc = new FastScanner();

     //    int n = sc.nextInt();
     //    long m = sc.nextLong();

     //    list  = new ArrayList<>();
     //    long sum = 0;
     //    for(int i = 0 ; i < n ; i++){

     //        long a = sc.nextLong();
     //        long b = sc.nextLong();

     //        list.add(a-b);
     //        sum += a;

     //    }

     //    if(sum <= m){
     //        System.out.println("0");
     //        return;
     //    }

     //    Collections.sort(list);

     //    for(int i = n-1 ; i > -1 ; i--){
     //        sum -= list.get(i);
     //        if(sum <= m){
     //            System.out.println(n-i);
     //            return;
     //        }
     //    }

     //    System.out.println("-1");

     // }

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

     public static void solve(){

        count = new int[100005];
        count1 = new int[100005];
        for(int i = 0 ; i < n ; i++){
            count[arr[i]] += 1;
            if(count[arr[i]] == 2){
                System.out.println("0");
                return;
            }
        }

        for(int i = 0 ; i < n; i++){

            count1[arr[i]&m] += 1;

            if((count[arr[i]&m] == 1) && ((arr[i]&m) != arr[i])){
                System.out.println("1");
                return;
            }

            if((count1[arr[i]&m] == 2)){
                System.out.println("2");
                return;
            }

        }

        System.out.println("-1");

     }

     public static void main(String[] args) {

            FastScanner sc = new FastScanner();
            // Scanner sc = new Scanner(System.in);
            // int t = sc.nextInt();
            int t = 1;
            // int l = 1;
            while(t > 0){

                // n = sc.nextInt();
                // n = sc.nextLong();
                // a = sc.nextLong();
                // b = sc.nextLong();
                // c = sc.nextLong();
                // d = sc.nextLong();

                // x = sc.nextLong();
                // y = sc.nextLong();

                // n = sc.nextLong();
                n = sc.nextInt();
                // n1 = sc.nextInt();

                m = sc.nextInt();

                // k = sc.nextLong();
                // s = sc.next();

                // ch = sc.next().toCharArray();
                // ch1 = sc.next().toCharArray();

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

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

                // mat = new Character[n][n];
                // for(int i = 0 ; i < n ; i++){
                //     String s = sc.next();
                //     for(int j = 0 ; j < n ; j++){
                //         mat[i][j] = s.charAt(j);
                //     }
                // }
                // str = new String[n];
                // for(int i = 0 ; i < n ; i++)
                //     str[i] = sc.next();

                // nodes = new Node[n];
                // for(int i = 0 ; i < n ;i++)
                //     nodes[i] = new Node(sc.nextInt(),sc.nextInt());

                // System.out.println(solve()?"YES":"NO");
                 solve();
                 // System.out.println(solve());
                 t -= 1;
            }

     }

    public static int log(long n){

         if(n == 0 || n == 1)
             return 0;

         if(n == 2)
             return 1;

         double num = Math.log(n);
         double den = Math.log(2);

         if(den == 0)
             return 0;

         return (int)(num/den);
     }

    public static boolean isPrime(long n) {
    // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
    }

     public static long gcd(long a,long b){

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

     }

     // public static void swap(int i,int j){
     //     long temp = arr[j];
     //     arr[j] = arr[i];
     //     arr[i] = temp;
     // }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class Node{
        int first;
        int second;
        Node(int f,int s){
            this.first = f;
            this.second = s;
        }
    }

     static class FastScanner {

                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st=new StringTokenizer("");
                String next() {
                        while (!st.hasMoreTokens())
                                try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        return st.nextToken();
                }

                int nextInt() {
                        return Integer.parseInt(next());
                }
                int[] readArray(int n) {
                        int[] a=new int[n];
                        for (int i=0; i<n; i++) a[i]=nextInt();
                        return a;
                }
                long nextLong() {
                        return Long.parseLong(next());
                }
        }

}


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

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

public class a{
     static int[] count,count1,count2;
     static Node[] nodes;
     static int[] arr;
     static int[] dp;
     static char[] ch,ch1;
     static int[] darr,farr;
     static Character[][] mat,mat1;
     static long x,h;
     static long maxl;
     static double dec;
     static String s;
     static long minl;
     static int mx = (int)1e9+5;
     static long mod = 998244353l;
     // static int minl = -1;
     // static long n;
     static int n,n1,n2;
     static long a;
     static long b;
     static long c;
     static long d;
     static long y,z;
     static int m;
     static long k;
     static String[] str,str1;
     static Set<Long> set,set1,set2;
     static List<Long> list,list1,list2,list3;
     static LinkedList<Node> ll;
     static Map<String,String> map;
     static StringBuilder sb,sb1,sb2;
     static int[] dx = {0,-1,0,1};
     static int[] dy = {-1,0,1,0};

     // public static void solve(){

     //    FastScanner sc = new FastScanner();

     //    int n = sc.nextInt();
     //    long m = sc.nextLong();

     //    list  = new ArrayList<>();
     //    long sum = 0;
     //    for(int i = 0 ; i < n ; i++){

     //        long a = sc.nextLong();
     //        long b = sc.nextLong();

     //        list.add(a-b);
     //        sum += a;

     //    }

     //    if(sum <= m){
     //        System.out.println("0");
     //        return;
     //    }

     //    Collections.sort(list);

     //    for(int i = n-1 ; i > -1 ; i--){
     //        sum -= list.get(i);
     //        if(sum <= m){
     //            System.out.println(n-i);
     //            return;
     //        }
     //    }

     //    System.out.println("-1");

     // }

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

     public static void solve(){

        count = new int[100005];
        for(int i = 0 ; i < n ; i++){
            count[arr[i]] += 1;
            if(count[arr[i]] == 2){
                System.out.println("0");
                return;
            }
        }

        for(int i = 0 ; i < n; i++){

            if((count[arr[i]&m] == 1) && ((arr[i]&m) != arr[i])){
                System.out.println(arr[i]);
                System.out.println("1");
                return;
            }
        }

        System.out.println("-1");

     }

     public static void main(String[] args) {

            FastScanner sc = new FastScanner();
            // Scanner sc = new Scanner(System.in);
            // int t = sc.nextInt();
            int t = 1;
            // int l = 1;
            while(t > 0){

                // n = sc.nextInt();
                // n = sc.nextLong();
                // a = sc.nextLong();
                // b = sc.nextLong();
                // c = sc.nextLong();
                // d = sc.nextLong();

                // x = sc.nextLong();
                // y = sc.nextLong();

                // n = sc.nextLong();
                n = sc.nextInt();
                // n1 = sc.nextInt();

                m = sc.nextInt();

                // k = sc.nextLong();
                // s = sc.next();

                // ch = sc.next().toCharArray();
                // ch1 = sc.next().toCharArray();

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

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

                // mat = new Character[n][n];
                // for(int i = 0 ; i < n ; i++){
                //     String s = sc.next();
                //     for(int j = 0 ; j < n ; j++){
                //         mat[i][j] = s.charAt(j);
                //     }
                // }
                // str = new String[n];
                // for(int i = 0 ; i < n ; i++)
                //     str[i] = sc.next();

                // nodes = new Node[n];
                // for(int i = 0 ; i < n ;i++)
                //     nodes[i] = new Node(sc.nextInt(),sc.nextInt());

                // System.out.println(solve()?"YES":"NO");
                 solve();
                 // System.out.println(solve());
                 t -= 1;
            }

     }

    public static int log(long n){

         if(n == 0 || n == 1)
             return 0;

         if(n == 2)
             return 1;

         double num = Math.log(n);
         double den = Math.log(2);

         if(den == 0)
             return 0;

         return (int)(num/den);
     }

    public static boolean isPrime(long n) {
    // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
    }

     public static long gcd(long a,long b){

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

     }

     // public static void swap(int i,int j){
     //     long temp = arr[j];
     //     arr[j] = arr[i];
     //     arr[i] = temp;
     // }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class Node{
        int first;
        int second;
        Node(int f,int s){
            this.first = f;
            this.second = s;
        }
    }

     static class FastScanner {

                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st=new StringTokenizer("");
                String next() {
                        while (!st.hasMoreTokens())
                                try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        return st.nextToken();
                }

                int nextInt() {
                        return Integer.parseInt(next());
                }
                int[] readArray(int n) {
                        int[] a=new int[n];
                        for (int i=0; i<n; i++) a[i]=nextInt();
                        return a;
                }
                long nextLong() {
                        return Long.parseLong(next());
                }
        }

}


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

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

public class a{
     static int[] count,count1,count2;
     static Node[] nodes;
     static int[] arr;
     static int[] dp;
     static char[] ch,ch1;
     static int[] darr,farr;
     static Character[][] mat,mat1;
     static long x,h;
     static long maxl;
     static double dec;
     static String s;
     static long minl;
     static int mx = (int)1e9+5;
     static long mod = 998244353l;
     // static int minl = -1;
     // static long n;
     static int n,n1,n2;
     static long a;
     static long b;
     static long c;
     static long d;
     static long y,z;
     static int m;
     static long k;
     static String[] str,str1;
     static Set<Long> set,set1,set2;
     static List<Long> list,list1,list2,list3;
     static LinkedList<Node> ll;
     static Map<String,String> map;
     static StringBuilder sb,sb1,sb2;
     static int[] dx = {0,-1,0,1};
     static int[] dy = {-1,0,1,0};

     // public static void solve(){

     //    FastScanner sc = new FastScanner();

     //    int n = sc.nextInt();
     //    long m = sc.nextLong();

     //    list  = new ArrayList<>();
     //    long sum = 0;
     //    for(int i = 0 ; i < n ; i++){

     //        long a = sc.nextLong();
     //        long b = sc.nextLong();

     //        list.add(a-b);
     //        sum += a;

     //    }

     //    if(sum <= m){
     //        System.out.println("0");
     //        return;
     //    }

     //    Collections.sort(list);

     //    for(int i = n-1 ; i > -1 ; i--){
     //        sum -= list.get(i);
     //        if(sum <= m){
     //            System.out.println(n-i);
     //            return;
     //        }
     //    }

     //    System.out.println("-1");

     // }

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

     public static void solve(){

        count = new int[100005];
        count1 = new int[100005];
        for(int i = 0 ; i < n ; i++){
            count[arr[i]] += 1;
            if(count[arr[i]] == 2){
                System.out.println("0");
                return;
            }
        }

        for(int i = 0 ; i < n; i++){

            count1[arr[i]&m] += 1;

            if(((count[arr[i]&m] == 1) && (arr[i]&m != arr[i]))){
                System.out.println("1");
                return;
            }

            if((count1[arr[i]&m] == 2)){
                System.out.println("2");
                return;
            }

        }

        System.out.println("-1");

     }

     public static void main(String[] args) {

            FastScanner sc = new FastScanner();
            // Scanner sc = new Scanner(System.in);
            // int t = sc.nextInt();
            int t = 1;
            // int l = 1;
            while(t > 0){

                // n = sc.nextInt();
                // n = sc.nextLong();
                // a = sc.nextLong();
                // b = sc.nextLong();
                // c = sc.nextLong();
                // d = sc.nextLong();

                // x = sc.nextLong();
                // y = sc.nextLong();

                // n = sc.nextLong();
                n = sc.nextInt();
                // n1 = sc.nextInt();

                m = sc.nextInt();

                // k = sc.nextLong();
                // s = sc.next();

                // ch = sc.next().toCharArray();
                // ch1 = sc.next().toCharArray();

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

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

                // mat = new Character[n][n];
                // for(int i = 0 ; i < n ; i++){
                //     String s = sc.next();
                //     for(int j = 0 ; j < n ; j++){
                //         mat[i][j] = s.charAt(j);
                //     }
                // }
                // str = new String[n];
                // for(int i = 0 ; i < n ; i++)
                //     str[i] = sc.next();

                // nodes = new Node[n];
                // for(int i = 0 ; i < n ;i++)
                //     nodes[i] = new Node(sc.nextInt(),sc.nextInt());

                // System.out.println(solve()?"YES":"NO");
                 solve();
                 // System.out.println(solve());
                 t -= 1;
            }

     }

    public static int log(long n){

         if(n == 0 || n == 1)
             return 0;

         if(n == 2)
             return 1;

         double num = Math.log(n);
         double den = Math.log(2);

         if(den == 0)
             return 0;

         return (int)(num/den);
     }

    public static boolean isPrime(long n) {
    // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
    }

     public static long gcd(long a,long b){

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

     }

     // public static void swap(int i,int j){
     //     long temp = arr[j];
     //     arr[j] = arr[i];
     //     arr[i] = temp;
     // }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class Node{
        int first;
        int second;
        Node(int f,int s){
            this.first = f;
            this.second = s;
        }
    }

     static class FastScanner {

                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st=new StringTokenizer("");
                String next() {
                        while (!st.hasMoreTokens())
                                try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        return st.nextToken();
                }

                int nextInt() {
                        return Integer.parseInt(next());
                }
                int[] readArray(int n) {
                        int[] a=new int[n];
                        for (int i=0; i<n; i++) a[i]=nextInt();
                        return a;
                }
                long nextLong() {
                        return Long.parseLong(next());
                }
        }

}


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

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

public class a{
     static int[] count,count1,count2;
     static Node[] nodes;
     static int[] arr;
     static int[] dp;
     static char[] ch,ch1;
     static int[] darr,farr;
     static Character[][] mat,mat1;
     static long x,h;
     static long maxl;
     static double dec;
     static String s;
     static long minl;
     static int mx = (int)1e9+5;
     static long mod = 998244353l;
     // static int minl = -1;
     // static long n;
     static int n,n1,n2;
     static long a;
     static long b;
     static long c;
     static long d;
     static long y,z;
     static int m;
     static long k;
     static String[] str,str1;
     static Set<Long> set,set1,set2;
     static List<Long> list,list1,list2,list3;
     static LinkedList<Node> ll;
     static Map<String,String> map;
     static StringBuilder sb,sb1,sb2;
     static int[] dx = {0,-1,0,1};
     static int[] dy = {-1,0,1,0};

     // public static void solve(){

     //    FastScanner sc = new FastScanner();

     //    int n = sc.nextInt();
     //    long m = sc.nextLong();

     //    list  = new ArrayList<>();
     //    long sum = 0;
     //    for(int i = 0 ; i < n ; i++){

     //        long a = sc.nextLong();
     //        long b = sc.nextLong();

     //        list.add(a-b);
     //        sum += a;

     //    }

     //    if(sum <= m){
     //        System.out.println("0");
     //        return;
     //    }

     //    Collections.sort(list);

     //    for(int i = n-1 ; i > -1 ; i--){
     //        sum -= list.get(i);
     //        if(sum <= m){
     //            System.out.println(n-i);
     //            return;
     //        }
     //    }

     //    System.out.println("-1");

     // }

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

     public static void solve(){

        count = new int[100005];
        for(int i = 0 ; i < n ; i++){
            count[arr[i]] += 1;
            if(count[arr[i]] == 2){
                System.out.println("0");
                return;
            }
        }

        for(int i = 0 ; i < n; i++){

            count[arr[i]&m] += 1;
            if((count[arr[i]&m] == 1) && ((arr[i]&m) != arr[i])){
                System.out.println(arr[i]);
                System.out.println("1");
                return;
            }
        }

        System.out.println("-1");

     }

     public static void main(String[] args) {

            FastScanner sc = new FastScanner();
            // Scanner sc = new Scanner(System.in);
            // int t = sc.nextInt();
            int t = 1;
            // int l = 1;
            while(t > 0){

                // n = sc.nextInt();
                // n = sc.nextLong();
                // a = sc.nextLong();
                // b = sc.nextLong();
                // c = sc.nextLong();
                // d = sc.nextLong();

                // x = sc.nextLong();
                // y = sc.nextLong();

                // n = sc.nextLong();
                n = sc.nextInt();
                // n1 = sc.nextInt();

                m = sc.nextInt();

                // k = sc.nextLong();
                // s = sc.next();

                // ch = sc.next().toCharArray();
                // ch1 = sc.next().toCharArray();

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

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

                // mat = new Character[n][n];
                // for(int i = 0 ; i < n ; i++){
                //     String s = sc.next();
                //     for(int j = 0 ; j < n ; j++){
                //         mat[i][j] = s.charAt(j);
                //     }
                // }
                // str = new String[n];
                // for(int i = 0 ; i < n ; i++)
                //     str[i] = sc.next();

                // nodes = new Node[n];
                // for(int i = 0 ; i < n ;i++)
                //     nodes[i] = new Node(sc.nextInt(),sc.nextInt());

                // System.out.println(solve()?"YES":"NO");
                 solve();
                 // System.out.println(solve());
                 t -= 1;
            }

     }

    public static int log(long n){

         if(n == 0 || n == 1)
             return 0;

         if(n == 2)
             return 1;

         double num = Math.log(n);
         double den = Math.log(2);

         if(den == 0)
             return 0;

         return (int)(num/den);
     }

    public static boolean isPrime(long n) {
    // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
    }

     public static long gcd(long a,long b){

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

     }

     // public static void swap(int i,int j){
     //     long temp = arr[j];
     //     arr[j] = arr[i];
     //     arr[i] = temp;
     // }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class Node{
        int first;
        int second;
        Node(int f,int s){
            this.first = f;
            this.second = s;
        }
    }

     static class FastScanner {

                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st=new StringTokenizer("");
                String next() {
                        while (!st.hasMoreTokens())
                                try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        return st.nextToken();
                }

                int nextInt() {
                        return Integer.parseInt(next());
                }
                int[] readArray(int n) {
                        int[] a=new int[n];
                        for (int i=0; i<n; i++) a[i]=nextInt();
                        return a;
                }
                long nextLong() {
                        return Long.parseLong(next());
                }
        }

}


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

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

public class a{
     static int[] count,count1,count2;
     static Node[] nodes;
     static int[] arr;
     static int[] dp;
     static char[] ch,ch1;
     static int[] darr,farr;
     static Character[][] mat,mat1;
     static long x,h;
     static long maxl;
     static double dec;
     static String s;
     static long minl;
     static int mx = (int)1e9+5;
     static long mod = 998244353l;
     // static int minl = -1;
     // static long n;
     static int n,n1,n2;
     static long a;
     static long b;
     static long c;
     static long d;
     static long y,z;
     static int m;
     static long k;
     static String[] str,str1;
     static Set<Long> set,set1,set2;
     static List<Long> list,list1,list2,list3;
     static LinkedList<Node> ll;
     static Map<String,String> map;
     static StringBuilder sb,sb1,sb2;
     static int[] dx = {0,-1,0,1};
     static int[] dy = {-1,0,1,0};

     // public static void solve(){

     //    FastScanner sc = new FastScanner();

     //    int n = sc.nextInt();
     //    long m = sc.nextLong();

     //    list  = new ArrayList<>();
     //    long sum = 0;
     //    for(int i = 0 ; i < n ; i++){

     //        long a = sc.nextLong();
     //        long b = sc.nextLong();

     //        list.add(a-b);
     //        sum += a;

     //    }

     //    if(sum <= m){
     //        System.out.println("0");
     //        return;
     //    }

     //    Collections.sort(list);

     //    for(int i = n-1 ; i > -1 ; i--){
     //        sum -= list.get(i);
     //        if(sum <= m){
     //            System.out.println(n-i);
     //            return;
     //        }
     //    }

     //    System.out.println("-1");

     // }

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

     public static void solve(){

        count = new int[100005];
        for(int i = 0 ; i < n ; i++){
            count[arr[i]] += 1;
            if(count[arr[i]] == 2){
                System.out.println("0");
                return;
            }
        }

        for(int i = 0 ; i < n; i++){

            if((count[arr[i]&m] == 1) && ((arr[i]&m) != arr[i])){
                System.out.println("1");
                return;
            }
        }

        System.out.println("-1");

     }

     public static void main(String[] args) {

            FastScanner sc = new FastScanner();
            // Scanner sc = new Scanner(System.in);
            // int t = sc.nextInt();
            int t = 1;
            // int l = 1;
            while(t > 0){

                // n = sc.nextInt();
                // n = sc.nextLong();
                // a = sc.nextLong();
                // b = sc.nextLong();
                // c = sc.nextLong();
                // d = sc.nextLong();

                // x = sc.nextLong();
                // y = sc.nextLong();

                // n = sc.nextLong();
                n = sc.nextInt();
                // n1 = sc.nextInt();

                m = sc.nextInt();

                // k = sc.nextLong();
                // s = sc.next();

                // ch = sc.next().toCharArray();
                // ch1 = sc.next().toCharArray();

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

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

                // mat = new Character[n][n];
                // for(int i = 0 ; i < n ; i++){
                //     String s = sc.next();
                //     for(int j = 0 ; j < n ; j++){
                //         mat[i][j] = s.charAt(j);
                //     }
                // }
                // str = new String[n];
                // for(int i = 0 ; i < n ; i++)
                //     str[i] = sc.next();

                // nodes = new Node[n];
                // for(int i = 0 ; i < n ;i++)
                //     nodes[i] = new Node(sc.nextInt(),sc.nextInt());

                // System.out.println(solve()?"YES":"NO");
                 solve();
                 // System.out.println(solve());
                 t -= 1;
            }

     }

    public static int log(long n){

         if(n == 0 || n == 1)
             return 0;

         if(n == 2)
             return 1;

         double num = Math.log(n);
         double den = Math.log(2);

         if(den == 0)
             return 0;

         return (int)(num/den);
     }

    public static boolean isPrime(long n) {
    // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
    }

     public static long gcd(long a,long b){

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

     }

     // public static void swap(int i,int j){
     //     long temp = arr[j];
     //     arr[j] = arr[i];
     //     arr[i] = temp;
     // }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class Node{
        int first;
        int second;
        Node(int f,int s){
            this.first = f;
            this.second = s;
        }
    }

     static class FastScanner {

                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st=new StringTokenizer("");
                String next() {
                        while (!st.hasMoreTokens())
                                try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        return st.nextToken();
                }

                int nextInt() {
                        return Integer.parseInt(next());
                }
                int[] readArray(int n) {
                        int[] a=new int[n];
                        for (int i=0; i<n; i++) a[i]=nextInt();
                        return a;
                }
                long nextLong() {
                        return Long.parseLong(next());
                }
        }

}


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

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

public class a{
     static int[] count,count1,count2;
     static Node[] nodes;
     static int[] arr;
     static int[] dp;
     static char[] ch,ch1;
     static int[] darr,farr;
     static Character[][] mat,mat1;
     static long x,h;
     static long maxl;
     static double dec;
     static String s;
     static long minl;
     static int mx = (int)1e9+5;
     static long mod = 998244353l;
     // static int minl = -1;
     // static long n;
     static int n,n1,n2;
     static long a;
     static long b;
     static long c;
     static long d;
     static long y,z;
     static int m;
     static long k;
     static String[] str,str1;
     static Set<Long> set,set1,set2;
     static List<Long> list,list1,list2,list3;
     static LinkedList<Node> ll;
     static Map<String,String> map;
     static StringBuilder sb,sb1,sb2;
     static int[] dx = {0,-1,0,1};
     static int[] dy = {-1,0,1,0};

     // public static void solve(){

     //    FastScanner sc = new FastScanner();

     //    int n = sc.nextInt();
     //    long m = sc.nextLong();

     //    list  = new ArrayList<>();
     //    long sum = 0;
     //    for(int i = 0 ; i < n ; i++){

     //        long a = sc.nextLong();
     //        long b = sc.nextLong();

     //        list.add(a-b);
     //        sum += a;

     //    }

     //    if(sum <= m){
     //        System.out.println("0");
     //        return;
     //    }

     //    Collections.sort(list);

     //    for(int i = n-1 ; i > -1 ; i--){
     //        sum -= list.get(i);
     //        if(sum <= m){
     //            System.out.println(n-i);
     //            return;
     //        }
     //    }

     //    System.out.println("-1");

     // }

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

     public static void solve(){

        count = new int[100005];
        count1 = new int[100005];
        for(int i = 0 ; i < n ; i++){
            count[arr[i]] += 1;
            if(count[arr[i]] == 2){
                System.out.println("0");
                return;
            }
        }

        int minl = -1;
        for(int i = 0 ; i < n; i++){

            count1[arr[i]&m] += 1;

            if(((count[arr[i]&m] == 1) && ((arr[i]&m) != arr[i]))){
                System.out.println("1");
                return;
            }

            if((count1[arr[i]&m] == 2)){
                System.out.println("2");
                minl = 2;
            }

        }

        System.out.println(minl);

     }

     public static void main(String[] args) {

            FastScanner sc = new FastScanner();
            // Scanner sc = new Scanner(System.in);
            // int t = sc.nextInt();
            int t = 1;
            // int l = 1;
            while(t > 0){

                // n = sc.nextInt();
                // n = sc.nextLong();
                // a = sc.nextLong();
                // b = sc.nextLong();
                // c = sc.nextLong();
                // d = sc.nextLong();

                // x = sc.nextLong();
                // y = sc.nextLong();

                // n = sc.nextLong();
                n = sc.nextInt();
                // n1 = sc.nextInt();

                m = sc.nextInt();

                // k = sc.nextLong();
                // s = sc.next();

                // ch = sc.next().toCharArray();
                // ch1 = sc.next().toCharArray();

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

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

                // mat = new Character[n][n];
                // for(int i = 0 ; i < n ; i++){
                //     String s = sc.next();
                //     for(int j = 0 ; j < n ; j++){
                //         mat[i][j] = s.charAt(j);
                //     }
                // }
                // str = new String[n];
                // for(int i = 0 ; i < n ; i++)
                //     str[i] = sc.next();

                // nodes = new Node[n];
                // for(int i = 0 ; i < n ;i++)
                //     nodes[i] = new Node(sc.nextInt(),sc.nextInt());

                // System.out.println(solve()?"YES":"NO");
                 solve();
                 // System.out.println(solve());
                 t -= 1;
            }

     }

    public static int log(long n){

         if(n == 0 || n == 1)
             return 0;

         if(n == 2)
             return 1;

         double num = Math.log(n);
         double den = Math.log(2);

         if(den == 0)
             return 0;

         return (int)(num/den);
     }

    public static boolean isPrime(long n) {
    // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
    }

     public static long gcd(long a,long b){

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

     }

     // public static void swap(int i,int j){
     //     long temp = arr[j];
     //     arr[j] = arr[i];
     //     arr[i] = temp;
     // }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class Node{
        int first;
        int second;
        Node(int f,int s){
            this.first = f;
            this.second = s;
        }
    }

     static class FastScanner {

                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st=new StringTokenizer("");
                String next() {
                        while (!st.hasMoreTokens())
                                try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        return st.nextToken();
                }

                int nextInt() {
                        return Integer.parseInt(next());
                }
                int[] readArray(int n) {
                        int[] a=new int[n];
                        for (int i=0; i<n; i++) a[i]=nextInt();
                        return a;
                }
                long nextLong() {
                        return Long.parseLong(next());
                }
        }

}


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

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

public class a{
     static int[] count,count1,count2;
     static Node[] nodes;
     static int[] arr;
     static int[] dp;
     static char[] ch,ch1;
     static int[] darr,farr;
     static Character[][] mat,mat1;
     static long x,h;
     static long maxl;
     static double dec;
     static String s;
     static long minl;
     static int mx = (int)1e9+5;
     static long mod = 998244353l;
     // static int minl = -1;
     // static long n;
     static int n,n1,n2;
     static long a;
     static long b;
     static long c;
     static long d;
     static long y,z;
     static int m;
     static long k;
     static String[] str,str1;
     static Set<Long> set,set1,set2;
     static List<Long> list,list1,list2,list3;
     static LinkedList<Node> ll;
     static Map<String,String> map;
     static StringBuilder sb,sb1,sb2;
     static int[] dx = {0,-1,0,1};
     static int[] dy = {-1,0,1,0};

     // public static void solve(){

     //    FastScanner sc = new FastScanner();

     //    int n = sc.nextInt();
     //    long m = sc.nextLong();

     //    list  = new ArrayList<>();
     //    long sum = 0;
     //    for(int i = 0 ; i < n ; i++){

     //        long a = sc.nextLong();
     //        long b = sc.nextLong();

     //        list.add(a-b);
     //        sum += a;

     //    }

     //    if(sum <= m){
     //        System.out.println("0");
     //        return;
     //    }

     //    Collections.sort(list);

     //    for(int i = n-1 ; i > -1 ; i--){
     //        sum -= list.get(i);
     //        if(sum <= m){
     //            System.out.println(n-i);
     //            return;
     //        }
     //    }

     //    System.out.println("-1");

     // }

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

     public static void solve(){

        count = new int[100005];
        count1 = new int[100005];
        for(int i = 0 ; i < n ; i++){
            count[arr[i]] += 1;
            if(count[arr[i]] == 2){
                System.out.println("0");
                return;
            }
        }

        for(int i = 0 ; i < n; i++){

            count1[arr[i]&m] += 1;

            if(((count[arr[i]&m] == 1) && (arr[i]&m != arr[i])){
                System.out.println("1");
                return;
            }

            if((count1[arr[i]&m] == 2)){
                System.out.println("2");
                return;
            }

        }

        System.out.println("-1");

     }

     public static void main(String[] args) {

            FastScanner sc = new FastScanner();
            // Scanner sc = new Scanner(System.in);
            // int t = sc.nextInt();
            int t = 1;
            // int l = 1;
            while(t > 0){

                // n = sc.nextInt();
                // n = sc.nextLong();
                // a = sc.nextLong();
                // b = sc.nextLong();
                // c = sc.nextLong();
                // d = sc.nextLong();

                // x = sc.nextLong();
                // y = sc.nextLong();

                // n = sc.nextLong();
                n = sc.nextInt();
                // n1 = sc.nextInt();

                m = sc.nextInt();

                // k = sc.nextLong();
                // s = sc.next();

                // ch = sc.next().toCharArray();
                // ch1 = sc.next().toCharArray();

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

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

                // mat = new Character[n][n];
                // for(int i = 0 ; i < n ; i++){
                //     String s = sc.next();
                //     for(int j = 0 ; j < n ; j++){
                //         mat[i][j] = s.charAt(j);
                //     }
                // }
                // str = new String[n];
                // for(int i = 0 ; i < n ; i++)
                //     str[i] = sc.next();

                // nodes = new Node[n];
                // for(int i = 0 ; i < n ;i++)
                //     nodes[i] = new Node(sc.nextInt(),sc.nextInt());

                // System.out.println(solve()?"YES":"NO");
                 solve();
                 // System.out.println(solve());
                 t -= 1;
            }

     }

    public static int log(long n){

         if(n == 0 || n == 1)
             return 0;

         if(n == 2)
             return 1;

         double num = Math.log(n);
         double den = Math.log(2);

         if(den == 0)
             return 0;

         return (int)(num/den);
     }

    public static boolean isPrime(long n) {
    // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
    }

     public static long gcd(long a,long b){

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

     }

     // public static void swap(int i,int j){
     //     long temp = arr[j];
     //     arr[j] = arr[i];
     //     arr[i] = temp;
     // }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class Node{
        int first;
        int second;
        Node(int f,int s){
            this.first = f;
            this.second = s;
        }
    }

     static class FastScanner {

                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st=new StringTokenizer("");
                String next() {
                        while (!st.hasMoreTokens())
                                try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        return st.nextToken();
                }

                int nextInt() {
                        return Integer.parseInt(next());
                }
                int[] readArray(int n) {
                        int[] a=new int[n];
                        for (int i=0; i<n; i++) a[i]=nextInt();
                        return a;
                }
                long nextLong() {
                        return Long.parseLong(next());
                }
        }

}


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

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

public class a{
     static int[] count,count1,count2;
     static Node[] nodes;
     static int[] arr;
     static int[] dp;
     static char[] ch,ch1;
     static int[] darr,farr;
     static Character[][] mat,mat1;
     static long x,h;
     static long maxl;
     static double dec;
     static String s;
     static long minl;
     static int mx = (int)1e9+5;
     static long mod = 998244353l;
     // static int minl = -1;
     // static long n;
     static int n,n1,n2;
     static long a;
     static long b;
     static long c;
     static long d;
     static long y,z;
     static int m;
     static long k;
     static String[] str,str1;
     static Set<Long> set,set1,set2;
     static List<Long> list,list1,list2,list3;
     static LinkedList<Node> ll;
     static Map<String,String> map;
     static StringBuilder sb,sb1,sb2;
     static int[] dx = {0,-1,0,1};
     static int[] dy = {-1,0,1,0};

     // public static void solve(){

     //    FastScanner sc = new FastScanner();

     //    int n = sc.nextInt();
     //    long m = sc.nextLong();

     //    list  = new ArrayList<>();
     //    long sum = 0;
     //    for(int i = 0 ; i < n ; i++){

     //        long a = sc.nextLong();
     //        long b = sc.nextLong();

     //        list.add(a-b);
     //        sum += a;

     //    }

     //    if(sum <= m){
     //        System.out.println("0");
     //        return;
     //    }

     //    Collections.sort(list);

     //    for(int i = n-1 ; i > -1 ; i--){
     //        sum -= list.get(i);
     //        if(sum <= m){
     //            System.out.println(n-i);
     //            return;
     //        }
     //    }

     //    System.out.println("-1");

     // }

     //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<-------------------

     public static void solve(){

        count = new int[100005];
        count1 = new int[100005];
        for(int i = 0 ; i < n ; i++){
            count[arr[i]] += 1;
            if(count[arr[i]] == 2){
                System.out.println("0");
                return;
            }
        }

        for(int i = 0 ; i < n; i++){

            count1[arr[i]&m] += 1;

            if(((count[arr[i]&m] == 1) && ((arr[i]&m) != arr[i]))){
                System.out.println("1");
                return;
            }

            if((count1[arr[i]&m] == 2)){
                System.out.println("2");
                return;
            }

        }

        System.out.println("-1");

     }

     public static void main(String[] args) {

            FastScanner sc = new FastScanner();
            // Scanner sc = new Scanner(System.in);
            // int t = sc.nextInt();
            int t = 1;
            // int l = 1;
            while(t > 0){

                // n = sc.nextInt();
                // n = sc.nextLong();
                // a = sc.nextLong();
                // b = sc.nextLong();
                // c = sc.nextLong();
                // d = sc.nextLong();

                // x = sc.nextLong();
                // y = sc.nextLong();

                // n = sc.nextLong();
                n = sc.nextInt();
                // n1 = sc.nextInt();

                m = sc.nextInt();

                // k = sc.nextLong();
                // s = sc.next();

                // ch = sc.next().toCharArray();
                // ch1 = sc.next().toCharArray();

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

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

                // mat = new Character[n][n];
                // for(int i = 0 ; i < n ; i++){
                //     String s = sc.next();
                //     for(int j = 0 ; j < n ; j++){
                //         mat[i][j] = s.charAt(j);
                //     }
                // }
                // str = new String[n];
                // for(int i = 0 ; i < n ; i++)
                //     str[i] = sc.next();

                // nodes = new Node[n];
                // for(int i = 0 ; i < n ;i++)
                //     nodes[i] = new Node(sc.nextInt(),sc.nextInt());

                // System.out.println(solve()?"YES":"NO");
                 solve();
                 // System.out.println(solve());
                 t -= 1;
            }

     }

    public static int log(long n){

         if(n == 0 || n == 1)
             return 0;

         if(n == 2)
             return 1;

         double num = Math.log(n);
         double den = Math.log(2);

         if(den == 0)
             return 0;

         return (int)(num/den);
     }

    public static boolean isPrime(long n) {
    // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
    }

     public static long gcd(long a,long b){

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

     }

     // public static void swap(int i,int j){
     //     long temp = arr[j];
     //     arr[j] = arr[i];
     //     arr[i] = temp;
     // }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class Node{
        int first;
        int second;
        Node(int f,int s){
            this.first = f;
            this.second = s;
        }
    }

     static class FastScanner {

                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st=new StringTokenizer("");
                String next() {
                        while (!st.hasMoreTokens())
                                try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        return st.nextToken();
                }

                int nextInt() {
                        return Integer.parseInt(next());
                }
                int[] readArray(int n) {
                        int[] a=new int[n];
                        for (int i=0; i<n; i++) a[i]=nextInt();
                        return a;
                }
                long nextLong() {
                        return Long.parseLong(next());
                }
        }

}