#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
bool pr[1000007];
void sieve(){pr[0]=1;pr[1]=1;for(int i=2;i<sqrt(1000007);i++){for(int j=2*i;j<=1000007;j+=i){pr[j]=1;}}}
ll fashtpower(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x;res%=MOD;y=y>>1;x=x*x;x%=MOD;}return res;}
ull lopow(ll x,ll y){ull res=1ULL;while(y){if(y&1)res*=(ull)x;y>>=1;x*=x;}return res;}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		float n;
		string s;
		cin>>n;
		cin>>s;
		float sum=0;
		int i=0;
		while(s[i]){
			sum+=(s[i]-48);
			i++;
		}
		//cout<<sum;
		if(sum<n){
			if(ceil(n-sum)/9==floor((n-sum)/9)){
					cout<<ceil((n-sum)/9)+1;
			}else{
					cout<<ceil((n-sum)/9);
			}
		}

		else{
			cout<<0;
		}

}


		#include<bits/stdc++.h>
		using namespace std;
		int main()
		{
			long long int a;
			string s;
			cin>>a>>s;
			long long int sum=0;
			vector<int> v;
			for(int i=0;i<s.length();i++)
			{
				sum+=s[i]-'0';
				v.push_back(s[i]-'0');
			}
			std::sort(v.begin(),v.end());
			if(sum>=a)
			cout<<0<<endl;
			else{
				int count=0;
				for(int i=0;i<v.size();i++)
				{
					if(v[i]<9)
					{
						sum=sum-v[i]+9;
						v[i]=9;
						count++;
					}
					if(sum>=a)
					{
						break;
					}
				}
				cout<<count;
			}
			return 0;
		}


		#include<bits/stdc++.h>
		using namespace std;
		int main()
		{
			long long int a;
			string s;
			cin>>a>>s;
			long long int sum=0;
			vector<int> v;
			for(int i=0;i<s.length();i++)
			{
				sum+=s[i]-'0';
				v.push_back(s[i]-'0');
			}
			std::sort(v.begin(),v.end());
			if(sum>=a)
			cout<<0<<endl;
			else{
				int count=1;
				for(int i=v.size()-1;i>=0;i--)
				{
					if(sum-v[i]+9>=a)
					{
						break;
					}
					count++;
				}
				cout<<count;
			}
			return 0;
		}


		#include<bits/stdc++.h>
		using namespace std;
		int main()
		{
			long long int a;
			string s;
			cin>>a>>s;
			long long int sum=0;
			vector<int> v;
			for(int i=0;i<s.length();i++)
			{
				sum+=s[i]-'0';
				v.push_back(s[i]-'0');
			}
			std::sort(v.begin(),v.end());
			if(sum>=a)
			cout<<0<<endl;
			else{
				int count=1;
				for(int i=0;i<v.size();i++)
				{
					if(sum-v[i]+9>=a)
					{
						break;
					}
					count++;
				}
				cout<<count;
			}
			return 0;
		}


		#include<bits/stdc++.h>
		using namespace std;
		int main()
		{
			long long int a;
			string s;
			cin>>a>>s;
			long long int sum=0;
			vector<int> v;
			for(int i=0;i<s.length();i++)
			{
				sum+=s[i]-'0';
				v.push_back(s[i]-'0');
			}
			std::sort(v.begin(),v.end());
			if(sum>=a)
			cout<<0<<endl;
			else{
				int count=0;
				for(int i=v.size()-1;i>=0;i--)
				{
					if(v[i]<9)
					{
						sum=sum-v[i]+9;
						v[i]=9;
						count++;
					}
					if(sum>=a)
					{
						break;
					}
				}
				cout<<count;
			}
			return 0;
		}


		#include<bits/stdc++.h>
		using namespace std;
		int main()
		{
			long long int a;
			string s;
			cin>>a>>s;
			long long int sum=0;
			for(int i=0;i<s.length();i++)
			{
				sum+=s[i]-'0';
			}
			if(sum>=a)
			cout<<0<<endl;
			else cout<<(a-sum)<<endl;
			return 0;
		}


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;

char str[100000];
int num[12];

int main()
{
	//while (true)
	//{

		int k;
		scanf("%d", &k);
		scanf("%s", str);
		int sum = 0;
		int len = strlen(str);
		for (int i = 0; i < len; i++) {
			sum += str[i] - '0';
			num[str[i] - '0']++;
		}
		if (sum >= k)
		{
			printf("0\n");
			return 0;
		}
		int tem = k - sum;
		int ans = 0;
		for (int i = 0; i <= 9; i++)
		{

			while (num[i] != 0)
			{
				sum += (9 - i);
				num[i]--;
				ans++;
				if (sum >= k) break;
			}
			if (sum >= k) break;

		}
		printf("%d\n", ans);

	//}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;

char str[100000];
int num[12];

int main()
{
	//while (true)
	//{

		int k;
		scanf("%d", &k);
		scanf("%s", str);
		int sum = 0;
		int len = strlen(str);
		for (int i = 0; i < len; i++) {
			sum += str[i] - '0';
			num[str[i] - '0']++;
		}
		if (sum >= k)
		{
			printf("0\n");
			return 0;
		}
		int tem = k - sum;
		int ans = 0;
		for (int i = 0; i <= 9; i++)
		{

			while (num[i] != 0)
			{
				sum += (9 - i);
				num[i]--;
				ans++;
			}
			//printf("%d\n", sum);
			if (sum >= k) break;
		}
		printf("%d\n", ans);

	//}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;

char str[100000];
int num[12];

int main()
{
	//while (true)
	//{

		int k;
		scanf("%d", &k);
		scanf("%s", str);
		int sum = 0;
		int len = strlen(str);
		for (int i = 0; i < len; i++) {
			sum += str[i] - '0';
			num[str[i] - '0']++;
		}
		if (sum >= k)
		{
			printf("0\n");
			return 0;
		}
		int tem = k - sum;
		int ans = 0;
		for (int i = 1; i <= 9; i++)
		{
			if (num[i] != 0)
			{
				sum += (9 - i);
				num[i]--;
				ans++;
			}
		}
		printf("%d\n", ans);
		return 0;
	//}
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;

char str[100000];
int num[12];

int main()
{
	//while (true)
	//{

		int k;
		scanf("%d", &k);
		scanf("%s", str);
		int sum = 0;
		int len = strlen(str);
		for (int i = 0; i < len; i++) {
			sum += str[i] - '0';
			num[str[i] - '0']++;
		}
		if (sum >= k)
		{
			printf("0\n");
			return 0;
		}
		int tem = k - sum;
		int ans = 0;
		for (int i = 0; i <= 9; i++)
		{
			if (num[i] != 0)
			{
				sum += (9 - i);
				num[i]--;
				ans++;
			}
			if (sum >= k) break;
		}
		printf("%d\n", ans);

	//}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;

char str[100000];
int num[12];

int main()
{
	//while (true)
	//{

		int k;
		scanf("%d", &k);
		scanf("%s", str);
		int sum = 0;
		int len = strlen(str);
		for (int i = 0; i < len; i++) {
			sum += str[i] - '0';
			num[str[i] - '0']++;
		}
		if (sum >= k)
		{
			printf("0\n");
			return 0;
		}
		int tem = k - sum;
		int ans = 0;
		for (int i = 1; i <= 9; i++)
		{
			if (num[i] != 0)
			{
				sum += (9 - i);
				num[i]--;
				ans++;
			}
			if (sum >= k) break;
		}
		printf("%d\n", ans);
		return 0;
	//}
}


#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;

char str[100000];
int num[12];

int main()
{
	//while (true)
	//{

		int k;
		scanf("%d", &k);
		scanf("%s", str);
		int sum = 0;
		int len = strlen(str);
		for (int i = 0; i < len; i++) {
			sum += str[i] - '0';
			num[str[i] - '0']++;
		}
		if (sum >= k)
		{
			printf("0\n");
			return 0;
		}
		int tem = k - sum;
		int ans = 0;
		for (int i = 1; i <= 9; i++)
		{
			if (num[i] != 0)
			{
				sum += (9 - i);
				num[i]--;
				ans++;
			}
		}
		printf("%d\n", ans);
		return 0;
	//}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

const int N=1e5+1e3+7;

int k;

char a[N];

int main()
{
	cin>>k;
	scanf("%s",a);
	int i=strlen(a);
	for(int j=0;j<i;j++)
		a[j]-=48;
	sort(a,a+i);
	for(int j=0;j<i;j++)
	{
		k-=a[j];
	}
	if(k<=0)
	{
		cout<<0;
		return 0;
	}
	for(int j=0;j<i;j++)
	{
		k-=9-a[j];
		if(k<=0)
		{
			cout<<j;
			break;
		}
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

const int N=1e5+1e3+7;

int k;

char a[N];

int main()
{
	cin>>k;
	scanf("%s",a);
	int i=strlen(a);
	for(int j=0;j<i;j++)
		a[j]-=48;
	sort(a,a+i);
	for(int j=0;j<i;j++)
	{
		k-=a[j];
	}
	if(k<=0)
	{
		cout<<0;
		return 0;
	}
	for(int j=0;j<i;j++)
	{
		k-=9-a[j];
		if(k<=0)
		{
			cout<<j+1;
			break;
		}
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

const int N=1e5+1e3+7;

int k;

char a[N];

int main()
{
	cin>>k;
	getchar();
	scanf("%s",a+1);
	for(int i=1;i<=strlen(a+1);i++)
		a[i]-=48;
	int i=strlen(a+1);
	sort(a+1,a+i+1);
	for(int j=1;j<=i;j++)
	{
		k-=a[j];
	}
	if(k<0)
	{
		cout<<0;
		return 0;
	}
	for(int j=1;j<=i;j++)
	{
		k-=9-a[j];
		if(k<=0)
		{
			cout<<j;
			break;
		}
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

const int N=1e5+1e3+7;

int k;

char a[N];

int main()
{
	cin>>k;
	getchar();
	scanf("%s",a+1);
	for(int i=1;i<=strlen(a+1);i++)
		a[i]-=48;
	int i=strlen(a+1);
	sort(a+1,a+i+1);
	for(int j=1;j<=i;j++)
	{
		k-=a[j];
	}
	if(k<0)
	{
		cout<<0;
		return 0;
	}
	for(int j=1;j<=i;j++)
	{
		k-=9-a[j];
		if(k<0)
		{
			cout<<j;
			break;
		}
	}
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

const int N=1e5+1e3+7;

int k;

char a[N];

int main()
{
	cin>>k;
	getchar();
	scanf("%s",a+1);
	for(int i=1;i<=strlen(a+1);i++)
		a[i]-=48;
	int i=strlen(a+1);
	sort(a+1,a+i+1);
	for(int j=1;j<=i;j++)
	{
		k-=a[j];
	}
	if(k<=0)
	{
		cout<<0;
		return 0;
	}
	for(int j=1;j<=i;j++)
	{
		k-=9-a[j];
		if(k<=0)
		{
			cout<<j;
			break;
		}
	}
}


#include <iostream>
using namespace std;

int main() {
    string n;
    int k, sum, t, i, ni, l;
    int c[10];
    cin >> k;
    cin >> n;
    l = n.length();
    for (i = 0; i < l; i++) {
        ni = n[i] - '0';
        sum += ni;
        c[ni] += 1;
        ni = 0;
    }
    sum = k - sum;
    for (i = 0; i < 10; i++) {
        if (sum <= c[i]*(9-i)) {
            if (sum % (9-i) == 0)
                t += (int)(sum / (9-i));
            else
                t += (int)(sum / (9-i)) + 1;
            break;
        }
        else {
            sum -= c[i] * (9-i);
            t += c[i];
        }
    }
    cout << t << endl;
}


#include <iostream>
using namespace std;

int main() {
    string n;
    int k, sum, t = 0, i, ni, l;
    int c[10];
    cin >> k;
    cin >> n;
    l = n.length();
    for (i = 0; i < l; i++) {
        ni = n[i] - '0';
        sum += ni;
        c[ni] += 1;
        ni = 0;
    }
    sum = k - sum;
    for (i = 0; i < 10; i++) {
        if (sum <= c[i]*(9-i)) {
            if (sum % (9-i) == 0)
                t += (int)(sum / (9-i));
            else
                t += (int)(sum / (9-i)) + 1;
            break;
        }
        else {
            sum -= c[i] * (9-i);
            t += c[i];
        }
    }
    cout << t << endl;
}


#include <iostream>
using namespace std;

int main() {
    string n;
    int k, sum, t, i, ni, l;
    int c[10];
    cin >> k;
    cin >> n;
    l = n.length();
    for (i = 0; i < l; i++) {
        ni = n[i] - '0';
        sum += ni;
        c[ni] += 1;
    }
    sum = k - sum;
    for (i = 0; i < 10; i++) {
        if (sum <= c[i]*(9-i)) {
            if (sum % (9-i) == 0)
                t += (int)(sum / (9-i));
            else
                t += (int)(sum / (9-i)) + 1;
            break;
        }
        else {
            sum -= c[i] * (9-i);
            t += c[i];
        }
    }
    cout << t << endl;
}


#include <iostream>
using namespace std;
    int c[10];

int main() {
    string n;
    int k, sum = 0, t = 0, i, ni, l;
    cin >> k;
    cin >> n;
    l = n.length();
    for (i = 0; i < l; i++) {
        ni = n[i] - '0';
        sum += ni;
        c[ni] += 1;
        ni = 0;
    }
    sum = k - sum;
    cout<<sum<<endl;
    for(i = 0; i <= 9; i++) cout<<c[i]<<" "; cout<<endl;
    if(sum <= 0)
    {
        cout<<0<<endl;
        return 0;
    }
    for (i = 0; i < 10; i++) {
        if (sum <= c[i]*(9-i)) {
            if (sum % (9-i) == 0)
                t += (int)(sum / (9-i));
            else
                t += (int)(sum / (9-i)) + 1;
            break;
        }
        else {
            sum -= c[i] * (9-i);
            t += c[i];
        }
    }
    cout << t << endl;
}


#include <iostream>
using namespace std;

int main() {
    string n;
    int k, sum = 0, t = 0, i, ni, l;
    int c[10];
    cin >> k;
    cin >> n;
    l = n.length();
    for (i = 0; i < l; i++) {
        ni = n[i] - '0';
        sum += ni;
        c[ni] += 1;
        ni = 0;
    }
    sum = k - sum;
    if(sum <= 0)
    {
        cout<<0<<endl;
        return 0;
    }
    for (i = 0; i < 10; i++) {
        if (sum <= c[i]*(9-i)) {
            if (sum % (9-i) == 0)
                t += (int)(sum / (9-i));
            else
                t += (int)(sum / (9-i)) + 1;
            break;
        }
        else {
            sum -= c[i] * (9-i);
            t += c[i];
        }
    }
    cout << t << endl;
}


#include <iostream>
using namespace std;

int main() {
    string n;
    int k, sum = 0, t = 0, i, ni, l;
    int c[10];
    cin >> k;
    cin >> n;
    l = n.length();
    for (i = 0; i < l; i++) {
        ni = n[i] - '0';
        sum += ni;
        c[ni] += 1;
        ni = 0;
    }
    sum = k - sum;
    for (i = 0; i < 10; i++) {
        if (sum <= c[i]*(9-i)) {
            if (sum % (9-i) == 0)
                t += (int)(sum / (9-i));
            else
                t += (int)(sum / (9-i)) + 1;
            break;
        }
        else {
            sum -= c[i] * (9-i);
            t += c[i];
        }
    }
    cout << t << endl;
}


#include <iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
    int c[10];

int main() {
    string n;
    int k, sum = 0, t = 0, i, ni, l;
    memset(c, 0, sizeof(c));
    cin >> k;
    cin >> n;
    l = n.length();
    for (i = 0; i < l; i++) {
        ni = n[i] - '0';
        sum += ni;
        c[ni] += 1;
        ni = 0;
    }
    sum = k - sum;
//    cout<<sum<<endl;
 //   for(i = 0; i <= 9; i++) cout<<c[i]<<" "; cout<<endl;
    if(sum <= 0)
    {
        cout<<0<<endl;
        return 0;
    }
    for (i = 0; i < 10; i++) {
        if (sum <= c[i]*(9-i)) {
            if (sum % (9-i) == 0)
                t += (int)(sum / (9-i));
            else
                t += (int)(sum / (9-i)) + 1;
            break;
        }
        else {
            sum -= c[i] * (9-i);
            t += c[i];
        }
    }
    cout << t << endl;
}


#include<iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;

int main()
{
	int k; // sum of digits
	cin >> k;
	long long int n; // new no
	cin >> n;
	vector<int> vec;
	long long int tmp=n;
	//cout << tmp << endl;
	while(tmp!=0)
	{
			int ele=tmp%10;
			//cout << ele << endl;
			vec.push_back(ele);
			tmp=tmp/10;
	}
	int sum=0;
	for(int i=0;i<vec.size();i++)
	{
		//cout << sum << endl;
		sum+=vec[i];
	}
	//cout << sum << endl;
	if(sum >= k) cout << 0 << endl;
	else{
		int diff= k-sum;
		//cout << diff << endl;
		sort(vec.begin(),vec.end());
		int count=1;
		for(int i=0;i<vec.size();i++)
		{
			int ele=vec[i];
			int increase=9-ele;
			if(increase <= diff) {diff=diff-increase;count++;}
			else break;
			//cout << diff << endl;
		}
		cout << count <<endl;

	}
	return 0;
}


#include<iostream>
#include<vector>
using namespace std;

int main()
{
	int k; // sum of digits
	cin >> k;
	int n; // new no
	cin >> n;
	vector<int> vec;
	int tmp=n;
	while(tmp!=0)
	{
			int ele=tmp%10;
			vec.push_back(ele);
			tmp=tmp/10;
	}
	int sum=0;
	for(int i=0;i<vec.size();i++)
	{
		sum+=vec[i];
	}
	if(sum >= k) cout << 0 << endl;
	else{
		int diff= k-sum;
		sort(vec.begin(),vec.end());
		int count=0;
		for(int i=0;i<vec.size();i++)
		{
			int ele=vec[i];
			int increase=9-ele;
			if(increase <= diff) {diff=diff-increase;count++;}
			else break;
		}
		cout << count <<endl;

	}
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;

int main()
{
	int k; // sum of digits
	cin >> k;
	int n; // new no
	cin >> n;
	vector<int> vec;
	int tmp=n;
	while(tmp!=0)
	{
			int ele=tmp%10;
			vec.push_back(ele);
			tmp=tmp/10;
	}
	int sum=0;
	for(int i=0;i<vec.size();i++)
	{
		sum+=vec[i];
	}
	if(sum >= k) cout << 0 << endl;
	else{
		int diff= k-sum;
		sort(vec.begin(),vec.end());
		int count=0;
		for(int i=0;i<vec.size();i++)
		{
			int ele=vec[i];
			int increase=9-ele;
			if(increase <= diff) {diff=diff-increase;count++;}
			else break;
		}
		cout << count <<endl;

	}
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;

int main()
{
	int k; // sum of digits
	cin >> k;
	int n; // new no
	cin >> n;
	vector<int> vec;
	int tmp=n;
	while(tmp!=0)
	{
			int ele=tmp%10;
			vec.push_back(ele);
			tmp=tmp/10;
	}
	int sum=0;
	for(int i=0;i<vec.size();i++)
	{
		sum+=vec[i];
	}
	if(sum >= k) cout << 0 << endl;
	else{
		int diff= k-sum;
		sort(vec.begin(),vec.end());
		int count=1;
		for(int i=0;i<vec.size();i++)
		{
			int ele=vec[i];
			int increase=9-ele;
			if(increase <= diff) {diff=diff-increase;count++;}
			else break;
		}
		cout << count <<endl;

	}
	return 0;
}


#include<iostream>
#include <bits/stdc++.h>
#include<vector>
using namespace std;

int main()
{
	int k; // sum of digits
	cin >> k;
	int n; // new no
	cin >> n;
	vector<int> vec;
	int tmp=n;
	while(tmp!=0)
	{
			int ele=tmp%10;
			vec.push_back(ele);
			tmp=tmp/10;
	}
	int sum=0;
	for(int i=0;i<vec.size();i++)
	{
		sum+=vec[i];
	}
	if(sum >= k) cout << 0 << endl;
	else{
		int diff= k-sum;
		sort(vec.begin(),vec.end());
		int count=0;
		for(int i=0;i<vec.size();i++)
		{
			int ele=vec[i];
			int increase=9-ele;
			if(increase <= diff) {diff=diff-increase;count++;}
			else break;
		}
		cout << count <<endl;

	}
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;

int main()
{
	int k; // sum of digits
	cin >> k;
	//long long int n; // new no
	string n;
	cin >> n;
	vector<int> vec;
	//long long int tmp=n;
	//cout << tmp << endl;
	for(int i=0;i<n.size();i++)
	{
		char c= n[i];
		int ele=(int)c;
		ele=ele-48;
		//cout << ele << endl;
		vec.push_back(ele);
	}
	int sum=0;
	for(int i=0;i<vec.size();i++)
	{
		//cout << sum << endl;
		sum+=vec[i];
	}
	//cout << sum << endl;
	if(sum >= k) cout << 0 << endl;
	else{
		int diff= k-sum;
		//cout << diff << endl;
		sort(vec.begin(),vec.end());
		int count=1;
		for(int i=0;i<vec.size();i++)
		{
			int ele=vec[i];
			int increase=9-ele;
			if(increase < diff) {diff=diff-increase;count++;}
			else break;
			//cout << diff << endl;
		}
		cout << count <<endl;

	}
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;

int main()
{
	int k; // sum of digits
	cin >> k;
	//long long int n; // new no
	string n;
	cin >> n;
	vector<int> vec;
	//long long int tmp=n;
	//cout << tmp << endl;
	for(int i=0;i<n.size();i++)
	{
		char c= n[i];
		int ele=(int)c;
		ele=ele-48;
		//cout << ele << endl;
		vec.push_back(ele);
	}
	int sum=0;
	for(int i=0;i<vec.size();i++)
	{
		//cout << sum << endl;
		sum+=vec[i];
	}
	//cout << sum << endl;
	if(sum >= k) cout << 0 << endl;
	else{
		int diff= k-sum;
		//cout << diff << endl;
		sort(vec.begin(),vec.end());
		int count=1;
		for(int i=0;i<vec.size();i++)
		{
			int ele=vec[i];
			int increase=9-ele;
			if(increase <= diff) {diff=diff-increase;count++;}
			else break;
			//cout << diff << endl;
		}
		cout << count <<endl;

	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL long long
LL k;
char n[100005];
LL num[10];
LL sum;
LL ans = 0;
int main()
{
    cin >> k >> n;
    int len = strlen(n);
    for(int i = 0; i < len; i++)
    {
        num[n[i]-'0']++;
        sum += n[i]-'0';
    }
    LL cha = k - sum;
    /*cout << cha << endl;
    for(int i = 0; i < 10; i++)
    {
        cout << num[i] << endl;
    }*/
    if(cha <= 0)
        cout << 0 << endl;
    else
    {
        for(int i = 0; i < 10; i++)
        {
            if(num[i] * (9-i) >= cha)
            {
                ans += (cha+1)/(9-i);
                break;
            }
            else
            {
                ans += num[i];
                cha -= num[i] * (9-i);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL long long
LL k;
char n[100005];
LL num[10];
LL sum;
LL ans = 0;
int main()
{
    cin >> k >> n;
    int len = strlen(n);
    for(int i = 0; i < len; i++)
    {
        num[n[i]-'0']++;
        sum += n[i]-'0';
    }
    LL cha = k - sum;
    /*cout << cha << endl;
    for(int i = 0; i < 10; i++)
    {
        cout << num[i] << endl;
    }*/
    if(cha <= 0)
        cout << 0 << endl;
    else
    {
        for(int i = 0; i < 10; i++)
        {
            if(num[i] * (9-i) >= cha)
            {
                ans += (cha-1)/(9-i)+1;
                //ans += cha/(9-i) + (cha%(9-i)!=0);
                break;
            }
            else
            {
                ans += num[i];
                cha -= num[i] * (9-i);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL long long
LL k;
char n[100005];
int num[10];
LL sum;
LL ans = 0;
int main()
{
    cin >> k >> n;
    int len = strlen(n);
    for(int i = 0; i < len; i++)
    {
        num[n[i]-'0']++;
        sum += n[i]-'0';
    }
    LL cha = k - sum;
    /*cout << cha << endl;
    for(int i = 0; i < 10; i++)
    {
        cout << num[i] << endl;
    }*/
    if(cha <= 0)
        cout << 0 << endl;
    else
    {
        for(int i = 0; i < 10; i++)
        {
            if(num[i]*(9-i) >= cha)
            {
                ans += (cha+1) / (9-i) + 1;
                break;
            }
            else
            {
                cha -= num[i]*(9-i);
                ans += num[i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}
/*
5*5   5
*/


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL long long
LL k;
char n[100005];
LL num[10];
LL sum;
LL ans = 0;
int main()
{
    cin >> k >> n;
    int len = strlen(n);
    for(int i = 0; i < len; i++)
    {
        num[n[i]-'0']++;
        sum += n[i]-'0';
    }
    LL cha = k - sum;
    /*cout << cha << endl;
    for(int i = 0; i < 10; i++)
    {
        cout << num[i] << endl;
    }*/
    if(cha <= 0)
        cout << 0 << endl;
    else
    {
        for(int i = 0; i < 10; i++)
        {
            if(num[i] * (9-i) >= cha)
            {
                ans += (cha+1)/(9-i)+1;
                break;
            }
            else
            {
                ans += num[i];
                cha -= num[i] * (9-i);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL long long
LL k;
char n[100005];
LL num[10];
LL sum;
LL ans = 0;
int main()
{
    cin >> k >> n;
    int len = strlen(n);
    for(int i = 0; i < len; i++)
    {
        num[n[i]-'0']++;
        sum += n[i]-'0';
    }
    LL cha = k - sum;
    /*cout << cha << endl;
    for(int i = 0; i < 10; i++)
    {
        cout << num[i] << endl;
    }*/
    if(cha <= 0)
        cout << 0 << endl;
    else
    {
        for(int i = 0; i < 10; i++)
        {
            if(num[i]*(9-i) >= cha)
            {
                for(int j = 1; j <= num[i]; j++)
                {
                    if(j*(9-i) >= cha)
                    {
                        ans ++;
                        break;
                    }
                    else
                    {
                        ans++;
                    }
                }
            }
            else
            {
                cha -= num[i]*(9-i);
                ans += num[i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}
/*
5*5   5
*/


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL long long
LL k;
char n[100005];
LL num[10];
LL sum;
LL ans = 0;
int main()
{
    cin >> k >> n;
    int len = strlen(n);
    for(int i = 0; i < len; i++)
    {
        num[n[i]-'0']++;
        sum += n[i]-'0';
    }
    LL cha = k - sum;
    /*cout << cha << endl;
    for(int i = 0; i < 10; i++)
    {
        cout << num[i] << endl;
    }*/
    if(cha <= 0)
        cout << 0 << endl;
    else
    {
        for(int i = 0; i < 10; i++)
        {
            if(num[i] * (9-i) >= cha)
            {
                ans += cha/(9-i) + (cha%(9-i)!= 0);
                break;
            }
            else
            {
                ans += num[i];
                cha -= num[i] * (9-i);
            }
        }
        cout << ans << endl;
    }
    return 0;
}
/*
5*5   5
*/


#include<iostream>
using namespace std;
int main()
{
    int k,s=0;
    string n;
    cin>>k>>n;
    int a[10];
    for(int i=0;i<n.size();i++)
    {
        a[int(n[i])-48]++;
        s+=int(n[i])-48;
    }
    int i=0,ans=0;
    while(s<k)
    {
        if(a[i]>0)
        {
            s+=9-i;
            ans++;
        }else
        {
            i++;
        }
    }
    cout<<ans;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int k,s=0;
    string n;
    cin>>k>>n;
    int a[10]={0};
    for(int i=0;i<n.size();i++)
    {
        a[int(n[i])-48]++;
        s+=int(n[i])-48;
    }
    int i=0,ans=0;

    while(s<k)
    {
        if(a[i]>0)
        {
            s+=9-i;
            ans++;
            a[i]--;
        }else
        {
            i++;
        }
    }
    cout<<ans;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int k,s=0;
    string n;
    cin>>k>>n;
    int a[10]={0};
    for(int i=0;i<n.size();i++)
    {
        a[int(n[i])-48]++;
        s+=int(n[i])-48;
    }
    int i=0,ans=0;

    while(s<k)
    {
        if(a[i]>0)
        {
            s+=9-i;
            ans++;
        }else
        {
            i++;
        }
        cout<<s<<"\n";
    }
    cout<<ans;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int k,s=0;
    string n;
    cin>>k>>n;
    int a[10]={0};
    for(int i=0;i<n.size();i++)
    {
        a[int(n[i])-48]++;
        s+=int(n[i])-48;
    }
    int i=0,ans=0;

    while(s<k)
    {
        if(a[i]>0)
        {
            s+=9-i;
            ans++;
        }else
        {
            i++;
        }
    }
    cout<<ans;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int k,s=0;
    string n;
    cin>>k>>n;
    int a[10]={0};
    for(int i=0;i<n.size();i++)
    {
        a[int(n[i])-48]++;
        s+=int(n[i])-48;
    }
    int i=0,ans=0;

    while(s<k)
    {
        if(a[i]>0)
        {
            s+=9-i;
            ans++;
            a[i]--;
        }else
        {
            i++;
        }
        cout<<s<<"\n";
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

long k;
string s;
long long sum=0, ans=0;

int main(){
    cin>>k;
    cin>>s;
    for (long i=0; i<s.size(); i++) sum+=(s[i]-48);
    if (sum>=k) cout<<0; else {
        while (k-sum>0) {
            long mini=0;
            for (long i=0; i<s.size(); i++) if (s[i]<s[mini]) mini=i;
            ans++;
            sum+=9-s[mini]+48;
            s.erase(mini,1);
        }
        cout<<ans;
    }
}


#include <bits/stdc++.h>
using namespace std;

long k;
string s;
long long sum=0, ans=0;
int d[100000]={0};

int main(){
    cin>>k;
    cin>>s;
    for (long i=0; i<s.size(); i++) sum+=(s[i]-48);
    if (sum>=k) cout<<0; else {
        while (k-sum>0) {
            long mini=0;
            for (long i=1; i<s.size(); i++) if (d[i]==0 && s[i]<s[mini]) mini=i;
            d[mini]=1;
            ans++;
            sum+=9-s[mini]+48;
        }
        cout<<ans;
    }
}


#include <bits/stdc++.h>
using namespace std;

long k;
string s;
long long sum=0, ans=0;

int main(){
    cin>>k;
    cin>>s;
    for (long i=0; i<s.size(); i++) sum+=(s[i]-48);
    if (sum>=k) cout<<0; else {
        while (k-sum>0) {
            long mini=0;
            for (long i=0; i<s.size(); i++) if (s[i]<s[mini]) mini=i;
            s.erase(mini,1);
            ans++;
            sum+=9-s[mini]+48;
        }
        cout<<ans;
    }
}


#include <bits/stdc++.h>
using namespace std;

long k;
string s;
long long sum=0, ans=0;

int main(){
    cin>>k;
    cin>>s;
    for (long i=0; i<s.size(); i++) sum+=(s[i]-48);
    if (sum>=k) cout<<0; else {
        sort(s.begin(),s.end());
        while (k-sum>0) {
            ans++;
            sum+=9-s[0]+48;
            s.erase(0,1);
        }
        cout<<ans;
    }
}


#include <bits/stdc++.h>
using namespace std;

long k;
string s;
long long n=0, sum=0, ans=0;

long long pow(long a){
    if (a==0) return 1; else
    if (a==1) return 10; else {
        long long temp=pow(a/2);
        if (a%2==1) return temp*temp*10; else return temp*temp;
    }
}

int main(){
    cin>>k;
    cin>>s;
    for (long i=0; i<s.size(); i++) sum+=(s[i]-48);
    if (sum>=k) cout<<0; else {
        long i=s.size()-1;
        while (((k-sum)>=(9-s[i]+48)) && i>=0) {
            ans=ans+(9-s[i]+48)*pow(s.size()-i-1);
            sum+=(9-s[i]+48);
            i--;
        }
        cout<<ans+(k-sum)*pow(s.size()-i-1);
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	long long int k, sum , diff, diff1, ans, num[10], i, l, count;
  string n;
	cin>>k>>n;
	sum = 0;
  l = n.length();
  for (i = 0; i < 10 ; i++){
    num[i]=0;
  }

  while( l>0) {
		sum = sum + (n[l-1] - '0');
    num['9' - n[l-1]]++;
		l--;
	}
	if (sum >= k) {
		cout<<0<<endl;
	} else {
	  count = 0;
    for (i = 9; i >= 0; i--) {
      if( sum + num[i]*i <= k) {
        count += num[i];
        sum += num[i]*i;
      } else if ((k-sum)/i == 0) {
        count += 1;
        break;
      }
      else {
        count += ( min( (k-sum)/i, num[i]));
        sum += min( (k-sum)/i, num[i]) * i;

      }

	}
  cout<<count;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  long long int k, sum , diff, diff1, ans, num[10000], i, l, count, c;
  string n;
  cin>>k>>n;
  sum = 0;
  l = n.length();
  for (i = 0; i < 10 ; i++){
    num[i]=0;
  }
  c = 0;
  while (l>0) {
  	sum = sum + (n[l-1] - '0');
    num[c++] = '9' - n[l-1];
  	l--;
  }
  sort(num,num+ c, greater<long long>());

  if (sum >= k) {
    cout<<0<<endl;
  } else {
    count = 0;
    c = 0;
    while( sum < k) {
      sum += num[c++];
      count++;
    }
  cout<<count<<endl;
  }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  long long int k, sum , diff, diff1, ans, num[10000], i, l, count, c;
  string n;
  cin>>k>>n;
  sum = 0;
  l = n.length();
  for (i = 0; i < 10 ; i++){
    num[i]=0;
  }
  c = 0;
  while (l>0) {
  	sum = sum + (n[l-1] - '0');
    num[c++] = '9' - n[l-1];
  	l--;
  }
  sort(num,num+ c);
  if (sum >= k) {
    cout<<0<<endl;
  } else {
    count = 0;
    c = 0;
    while( sum < k) {
      sum += num[c++];
      count++;
    }
  cout<<count<<endl;
  }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	long long int k, sum , diff, diff1, ans, l ;
  string n;
	cin>>k>>n;
	sum = 0;
  l = n.length();
	while( l>0) {
		sum = sum + (n[l-1] - '0');
		l--;
	}
	if (sum >= k) {
		cout<<0<<endl;
	} else {
		diff = k - sum;
		diff1 = diff/9;
		ans =  (diff%9 == 0) ? diff1: diff1+1 ;
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  long long int k, sum , diff, diff1, ans, num[10000], i, l, count, c;
  string n;
  cin>>k>>n;
  sum = 0;
  l = n.length();
  for (i = 0; i < 10 ; i++){
    num[i]=0;
  }
  c = 0;
  while (l>0) {
  	sum = sum + (n[l-1] - '0');
    num[c++] = '9' - n[l-1];
  	l--;
  }
  sort(num,num+ c);
  if (sum >= k) {
    cout<<0<<endl;
  } else {
    count = 0;
    c = 0;
    while( sum < k) {
      sum += num[c++];
      count++;
    }
  }

  cout<<count<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  long long int k, sum , diff, diff1, ans, num[10000], i, l, count, c;
  string n;
  cin>>k>>n;
  sum = 0;
  l = n.length();
  for (i = 0; i < 10 ; i++){
    num[i]=0;
  }
  c = 0;
  while (l>0) {
  	sum = sum + (n[l-1] - '0');
    num[c++] = '9' - n[l-1];
  	l--;
  }
  sort(num,num+ c, greater<long long>());
  for(i=0;i<c;i++) {
    cout<<num[i]<<endl;
  }
  if (sum >= k) {
    cout<<0<<endl;
  } else {
    count = 0;
    c = 0;
    while( sum < k) {
      sum += num[c++];
      count++;
    }
  cout<<count<<endl;
  }

return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n ,k;
    cin>>n>>k;
    int num [100000+1]={0};
    int anded[100000+1]={0};
    int temp ;
    while(n--)
    {
        cin >>temp;
        num[temp]++;
        if ( (temp&k) !=temp)
            anded[temp&k]++;

        if (num[temp]>1)
        {
            cout<<0;
            return 0;
        }
    }
    for (int i =0 ; i< 100000+1 ;i++)
    {
        if (num [i] ==1 && anded[i]>0 )
            {

                cout<<1;
                return 0;
            }
        else if (anded [i]>1)
            {
                cout<<2;
                return 0;
            }

    }
    cout <<-1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n ,x;
    cin>>n>>x;
    int a[n];
    bool a_ch[100001]={0};
    for (int i =0;i<n ; i++)
        {
            cin>>a[i];
            a_ch[a[i]]++;
        }
    int sum =0;
    for (int i =0 ; i< n ;i++)
    {
        if (a_ch[a[i]&x] && (a[i]&x) != a[i])
            sum++;
    }
    cout<<sum;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n ,num;
    cin>>n>>num;
    int x[n];
    for (int i =0 ; i< n ; i++)
        cin>>x[i];

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

        for (int j =0 ; j<n  ; )
        {
            j+=((i==j+1) && j+1 <n)? 2:1;
            if (x[i]==x[j])
            {
                cout<<0;
                return 0 ;
            }

        }

        int temp=x[i]#

        for (int j =0 ;j<n ;  )
        {
            j+=((i==j+1) && j+1 <n)? 2:1;

            if (temp==x[j]  )
            {
                cout<<1;
                return 0 ;
            }

        }
        x[i]&=num;

        for (int j =0 ;j<n ;  )
        {
            j+=((i==j+1) && j+1 <n)? 2:1;

            if (x[i]==(x[j]&num))
            {
                cout<<2;
                return 0 ;
            }

        }

    }

    cout<<-1;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n ,k;
    cin>>n>>k;
    int num [100000+1]={0};
    int anded[100000+1]={0};
    int temp ;
    while(n--)
    {
        cin >>temp;
        num[temp]++;
        if ( (temp&k) !=temp)
            anded[temp&k]++;

        if (num[temp]>1)
        {
            cout<<0;
            return 0;
        }
    }
    for (int i =0 ; i< 100000+1 ;i++)
    {
        if (num [i]==anded[i] && num[i]!=0)
            {

                cout<<1;
                return 0;
            }
        else if (anded [i]>1)
            {
                cout<<2;
                return 0;
            }

    }
    cout <<-1;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n ,num;
    cin>>n>>num;
    int x[n];
    for (int i =0 ; i< n ; i++)
        cin>>x[i];

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

        for (int j =0 ; j<n  ; )
        {
            j+=((i==j+1) && j+1 <n)? 2:1;
            if (x[i]==x[j])
            {
                cout<<0;
                return 0 ;
            }

        }
    }

    for (int i =0 ; i< n ; i++)
    {
        int temp=x[i]#

        for (int j =0 ;j<n ;  )
        {
            j+=((i==j+1) && j+1 <n)? 2:1;

            if (temp==x[j]  )
            {
                cout<<1;
                return 0 ;
            }

        }

    }

    for (int i =0 ; i< n ; i++)
    {
        x[i]&=num;

        for (int j =0 ;j<n ;  )
        {
            j+=((i==j+1) && j+1 <n)? 2:1;

            if (x[i]==(x[j]&num))
            {
                cout<<2;
                return 0 ;
            }

        }

    }

    cout<<-1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n ,x;
    cin>>n>>x;
    int a[n];
    int  a_ch[100001]={0};
    for (int i =0;i<n ; i++)
        {
            cin>>a[i];
            a_ch[a[i]]++;
            if (a_ch[a[i]]>1)
            {
                cout<<"0"<<endl;
                return 0;
            }
        }
    int sum =0;
    for (int i =0 ; i< n ;i++)
    {

         if  (a_ch[a[i]&x] && (a[i]&x) != a[i])
            sum++;
    }
    (sum==0)?cout<<-1:cout<<sum;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n ,num;
    cin>>n>>num;
    int x1[100001]={0};
    int x2[100001]={0};
        int temp;
    for (int i =0 ; i< n ; i++)
        {
            cin>>temp;
            x1[temp]++;
            x2[temp&num]++;
        }

        int max =0;
        for (int i =100000 ; i>=0 ; i-- )
        {
            if (x1[i]>0)
            {
                max =i;
                break;
            }
        }
        for (int i =0 ; i<=max ; i++ )
        {
            if (x1[i]>1)
            {
                cout<<0;
                return 0;
            }
        }
        for (int i =0 ; i<=100000 ; i++ )
        {
            if ( x2[i]==2 && x1[i]==1)
            {
                cout<<1;
                return 0;
            }
            else if (x2[i]==2 && x1[i]==0)
            {
                cout<<2;
                return 0;
            }
        }

    cout<<-1;
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>

#define x first
#define y second
#define sqr(a) ((a) * (a)
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> par;
typedef string str;

void start();
void stop();
void out(int);

ll a[200020];
map<ll, ll> b, c;

void solve()
{
	ll n, xx;
	cin >> n >> xx;
	c.clear();
	b.clear();

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[a[i]]++;
		if ((a[i] & xx) != a[i])
			b[a[i] & xx]++;
		c[a[i]]++;
	}

	for (auto i : c)
		if (i.y >= 2)
		{
			cout << 0 << endl;
			return;
		}

	for (auto i : b)
		if (i.y >= 2)
		{
			cout << 2 - c[i.x] << endl;
			return;
		}

	cout << -1 << endl;

	/*ll n;
	cin >> n;
	for (int i = 0; i < 2 * n; i++)
		cin >> a[i], c[a[i]]++;
	for (auto i : c)
		if (i.y >= n)
		{
			cout << 0 << endl;
			return;
		}
		else
		{
			ll m = n - i.y;

		}*/
}

int main()
{
	start();
	solve();
	stop();
    return 0;
}
void start()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
void out(int a)
{
	cout << setprecision(a) << fixed;
}
void stop()
{
	//system("pause");
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>

#define x first
#define y second
#define sqr(a) ((a) * (a)
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> par;
typedef string str;

void start();
void stop();
void out(int);

ll a[100000];
map<ll, ll> b, c;

void solve()
{
	ll n, x;
	cin >> n >> x;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[a[i] & x]++;
		if ((a[i] & x) != a[i])
			b[a[i]]++;
		c[a[i]]++;
	}
	for (auto i : c)
		if (i.y >= 2)
		{
			cout << 0 << endl;
			return;
		}
	for (auto i : b)
	{
		if (i.y >= 2)
		{
			ll k = 0;
			for (int j = 0; j < n; j++)
				if (a[j] == i.x)
					k++;
			if (k >= 2)
				cout << 0;
			else
				if (k == 1)
					cout << 1;
				else
					cout << 2;
			cout << endl;
			return;
		}
	}
	cout << -1 << endl;
}

int main()
{
	start();
	solve();
	stop();
    return 0;
}
void start()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
void out(int a)
{
	cout << setprecision(a) << fixed;
}
void stop()
{
	//system("pause");
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>

#define x first
#define y second
#define sqr(a) ((a) * (a)
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> par;
typedef string str;

void start();
void stop();
void out(int);

ll a[200020];
map<ll, ll> b, c;

void solve()
{
	ll n, xx;
	cin >> n >> xx;
	c.clear();
	b.clear();

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[a[i]]++;
		if ((a[i] & xx) != a[i])
			b[a[i] & xx]++;
		c[a[i]]++;
	}

	for (auto i : c)
		if (i.y >= 2)
		{
			cout << 0 << endl;
			return;
		}
ll ans = 5;
	for (auto i : b)
		if (i.y >= 2)
		{
			ans = min(ans, 2 - c[i.x]);
		}
if (ans == 5)
	cout << -1 << endl;
	else
	cout << ans << endl;

	/*ll n;
	cin >> n;
	for (int i = 0; i < 2 * n; i++)
		cin >> a[i], c[a[i]]++;
	for (auto i : c)
		if (i.y >= n)
		{
			cout << 0 << endl;
			return;
		}
		else
		{
			ll m = n - i.y;

		}*/
}

int main()
{
	start();
	solve();
	stop();
    return 0;
}
void start()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
void out(int a)
{
	cout << setprecision(a) << fixed;
}
void stop()
{
	//system("pause");
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>

#define x first
#define y second
#define sqr(a) ((a) * (a)
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> par;
typedef string str;

void start();
void stop();
void out(int);

ll a[200020];
map<ll, ll> b, c;

void solve()
{
	ll n, xx;
	cin >> n >> xx;

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[(a[i] & xx)]++;
		if ((a[i] & xx) != a[i])
			b[a[i]]++;
		c[a[i]]++;
	}

	for (auto i : c)
		if (i.y >= 2)
		{
			cout << 0 << endl;
			return;
		}

	for (auto i : b)
		if (i.y >= 2)
		{
			cout << 2 - c[i.x] << endl;
			return;
		}

	cout << -1 << endl;

	/*ll n;
	cin >> n;
	for (int i = 0; i < 2 * n; i++)
		cin >> a[i], c[a[i]]++;
	for (auto i : c)
		if (i.y >= n)
		{
			cout << 0 << endl;
			return;
		}
		else
		{
			ll m = n - i.y;

		}*/
}

int main()
{
	start();
	solve();
	stop();
    return 0;
}
void start()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
void out(int a)
{
	cout << setprecision(a) << fixed;
}
void stop()
{
	//system("pause");
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>

#define x first
#define y second
#define sqr(a) ((a) * (a)
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> par;
typedef string str;

void start();
void stop();
void out(int);

ll a[100000];
map<ll, ll> b, c;

void solve()
{
	ll n, x;
	cin >> n >> x;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[a[i] & x]++;
		if ((a[i] & x) != a[i])
			b[a[i]]++;
		c[a[i]]++;
	}
	for (auto i : c)
		if (i.y >= 2)
		{
			cout << 0 << endl;
			return;
		}

	for (auto i : b)
		if (i.y >= 2)
		{
			ll k = 0;
			for (int j = 0; j < n; j++)
				if (a[j] == i.x)
					k++;
			cout << 2 - k << endl;
			return;
		}
	cout << -1 << endl;
}

int main()
{
	start();
	solve();
	stop();
    return 0;
}
void start()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
void out(int a)
{
	cout << setprecision(a) << fixed;
}
void stop()
{
	//system("pause");
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>

#define x first
#define y second
#define sqr(a) ((a) * (a)
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> par;
typedef string str;

void start();
void stop();
void out(int);

ll a[200020];
map<ll, ll> b, c;

void solve()
{
	ll n, xx;
	cin >> n >> xx;

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[(a[i] & xx)]++;
		if ((a[i] & xx) != a[i])
			b[a[i]]++;
		c[a[i]]++;
	}

	for (auto i : b)
		cout << i.x << ' ' << i.y << endl;
	cout << endl;
	for (auto i : c)
		cout << i.x << ' ' << i.y << endl;

	for (auto i : c)
		if (i.y >= 2)
		{
			cout << 0 << endl;
			return;
		}

	for (auto i : b)
		if (i.y >= 2)
		{
			cout << i.y - 1 << endl;
			return;
		}

	cout << -1 << endl;

	/*ll n;
	cin >> n;
	for (int i = 0; i < 2 * n; i++)
		cin >> a[i], c[a[i]]++;
	for (auto i : c)
		if (i.y >= n)
		{
			cout << 0 << endl;
			return;
		}
		else
		{
			ll m = n - i.y;

		}*/
}

int main()
{
	start();
	solve();
	stop();
    return 0;
}
void start()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
void out(int a)
{
	cout << setprecision(a) << fixed;
}
void stop()
{
//	system("pause");
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>

#define x first
#define y second
#define sqr(a) ((a) * (a)
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> par;
typedef string str;

void start();
void stop();
void out(int);

ll a[200020];
map<ll, ll> b, c;

void solve()
{
	ll n, xx;
	cin >> n >> xx;

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[(a[i] & xx)]++;
		if ((a[i] & xx) != a[i])
			b[a[i]]++;
		c[a[i]]++;
	}

	for (auto i : c)
		if (i.y >= 2)
		{
			cout << 0 << endl;
			return;
		}

	for (auto i : b)
		if (i.y >= 2)
		{
			cout << i.y - 1 << endl;
			return;
		}

	cout << -1 << endl;

	/*ll n;
	cin >> n;
	for (int i = 0; i < 2 * n; i++)
		cin >> a[i], c[a[i]]++;
	for (auto i : c)
		if (i.y >= n)
		{
			cout << 0 << endl;
			return;
		}
		else
		{
			ll m = n - i.y;

		}*/
}

int main()
{
	start();
	solve();
	stop();
    return 0;
}
void start()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
void out(int a)
{
	cout << setprecision(a) << fixed;
}
void stop()
{
//	system("pause");
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>

#define x first
#define y second
#define sqr(a) ((a) * (a)
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> par;
typedef string str;

void start();
void stop();
void out(int);

ll a[100010];
map<ll, ll> b, c;

void solve()
{
	ll n, x;
	cin >> n >> x;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[(a[i] & x)]++;
		if ((a[i] & x) != a[i])
			b[a[i]]++;
		c[a[i]]++;
	}

	for (auto i : c)
		if (i.y >= 2)
		{
			cout << 0 << endl;
			return;
		}

	for (auto i : b)
		if (i.y >= 2)
		{
			cout << 2 - c[i.x] << endl;
			return;
		}

	cout << -1 << endl;
}

int main()
{
	start();
	solve();
	stop();
    return 0;
}
void start()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
void out(int a)
{
	cout << setprecision(a) << fixed;
}
void stop()
{
	//system("pause");
}


#include <iostream>
#include <algorithm>

using namespace std;

bool test(int i,int l,int b[],int n) {
	bool temp = false;
	for (unsigned int k = 0; k < n; k++) {
		if (k != l) {
			if (b[k] == i) {
				temp = true;
				break;
			}
		}
	}
	return temp;
}

bool selftest(int b[],int n) {
	int temp = false;
	sort(b , b+n);
	for (int i = 0; i < n;i++) {
		if (b[i]==b[i+1]) {
			temp = true;
			break;
		}
	}
	return temp;
}

int main() {
	int n;
	cin >> n;
	int x;
	cin >> x;
	int a[100500];
	int b[100500];
	int result = -1;

	for (int i = 0; i < n; i++) {
		int k;cin >> k;
		a[i]=k;
	}

	if (selftest(a,n) == true) {
		result = 0;
	}

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

			if (test((a[i]& x), i, a, n) == true) {
				result = 1;
				break;
			}
			else {
				b[i]=(a[i]&x);
				sort(b,b+i+1);
				if (i > 0) {
					if (b[i]==b[i-1]) {
						result = 2;
						break;
					}
				}
			}
		}
	}

	cout << result;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool test(int i,int l,vector<int> b) {
	bool temp = false;
	for (unsigned int k = 0; k < b.size(); k++) {
		if (k != l) {
			if (b[k] == i) {
				temp = true;
				break;
			}
		}
	}
	return temp;
}

bool selftest(vector<int> b) {
	int temp = false;
	sort(b.begin(), b.end());
	for (int i = 0; i < (b.size()-1);i++) {
		if (b[i]==b[i+1]) {
			temp = true;
			break;
		}
	}
	return temp;
}

int main() {
	int n;
	cin >> n;
	int x;
	cin >> x;
	vector<int> a;
	vector<int> b;
	int result = -1;

	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		a.push_back(k);
	}

	if (selftest(a) == true) {
		result = 0;
	}

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

			if (test((a[i]& x), i, a) == true) {
				result = 1;
				break;
			}
			else {
				b.push_back((a[i] & x));
				sort(b.begin(),b.end());
				if (i > 0) {
					if (b[i]==b[i-1]) {
						result = 2;
						break;
					}
				}
			}
		}
	}

	cout << result;
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int fun(int a, int b) {
	int l = a;
	int m = b;
	int temp = 0;
	int pow = 1;
	for (int i = 0;; i++) {

		if (l % 2 == 1 && m % 2 == 1) {
			temp += pow;
		}

		if ((l == 0) || (m == 0)) {
			break;
		}

		l = l / 2;
		m = m / 2;
		pow = pow * 2;

	}
	return temp;
}

bool test(int i,int l,vector<int> b) {
	bool temp = false;
	for (unsigned int k = 0; k < b.size(); k++) {
		if (k != l) {
			if (b[k] == i) {
				temp = true;
				break;
			}
		}
	}
	return temp;
}

bool selftest(vector<int>b) {
	int temp = false;
	for (int i = b.size()-1; i >=0; i--) {
		if (test(b[i], i, b)==true) {
			temp = true;
			break;
		}
		b.pop_back();
	}
	return temp;
}

int main() {
	int n;
	cin >> n;
	int x;
	cin >> x;
	vector<int> a;
	vector<int> b;
	int result = -1;

	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		a.push_back(k);
	}

	for (int i = 0; i < n; i++) {
		if (selftest(a) == true) {
			result = 0;
			break;
		}

	}

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

			if (test(fun(a[i], x), i, a) == true) {
				result = 1;
				break;
			}
			else {
				b.push_back(fun(a[i], x));
			}
		}
	}

	if (result == -1) {
		for (int i = 0; i < n; i++) {
			if (selftest(b)==true) {
				result = 2;
				break;
			}
		}
	}
	cout << result;
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

/*int fun(int a, int b) {
	int l = a;
	int m = b;
	int temp = 0;
	int pow = 1;
	for (int i = 0;; i++) {

		if (l % 2 == 1 && m % 2 == 1) {
			temp += pow;
		}

		if ((l == 0) || (m == 0)) {
			break;
		}

		l = l / 2;
		m = m / 2;
		pow = pow * 2;

	}
	return temp;
}*/

bool test(int i,int l,vector<int> b) {
	bool temp = false;
	for (unsigned int k = 0; k < b.size(); k++) {
		if (k != l) {
			if (b[k] == i) {
				temp = true;
				break;
			}
		}
	}
	return temp;
}

bool selftest(vector<int>b) {
	int temp = false;
	for (int i = b.size()-1; i >=0; i--) {
		if (test(b[i], i, b)==true) {
			temp = true;
			break;
		}
		b.pop_back();
	}
	return temp;
}

int main() {
	int n;
	cin >> n;
	int x;
	cin >> x;
	vector<int> a;
	vector<int> b;
	int result = -1;

	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		a.push_back(k);
	}

	for (int i = 0; i < n; i++) {
		if (selftest(a) == true) {
			result = 0;
			break;
		}

	}

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

			if (test((a[i]& x), i, a) == true) {
				result = 1;
				break;
			}
			else {
				b.push_back((a[i] & x));
			}
		}
	}

	if (result == -1) {
		for (int i = 0; i < n; i++) {
			if (selftest(b)==true) {
				result = 2;
				break;
			}
		}
	}
	cout << result;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n; cin >> n;
	int k; cin >> k;
	bool temp[100003] = {};
	bool tempa[100003] = {};
	bool tempa1[100003] = {};
	vector<int> in;
	vector<int> ina;

	int out = -1;

	for (int i = 0; i < n;i++) {
		int l; cin >> l;
		if (temp[l] == true) {
			out = 0;
			break;
		}
			in.push_back(l);
		temp[l] = true;
	}

	if (out != 0) {
		for (int i = 0; i < n; i++) {
			if ((in[i]&k) != in[i]) {
				if(temp[in[i]&k]==true){
					out = 1;
					break;
				}
			}
			ina.push_back(in[i]&k);

			if (tempa[ina[i]]==true) {
				tempa1[ina[i]] = true;
			}
			tempa[ina[i]] = true;
		}
	}

	if (out == -1) {
		for (int i = 0; i < n; i++) {
			if (tempa1[ina[i]] == true) {
				out = 2;
				break;
			}
		}
	}
	cout << out;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

bool test(int i,int l,int b[],int n) {
	bool temp = false;
	for (unsigned int k = 0; k < n; k++) {
		if (k != l) {
			if (b[k] == i) {
				temp = true;
				break;
			}
		}
	}
	return temp;
}

bool selftest(int b[],int n) {
	int temp = false;
	sort(b , b+n);
	for (int i = 0; i < n;i++) {
		if (b[i]==b[i+1]) {
			temp = true;
			break;
		}
	}
	return temp;
}

int main() {
	int n;
	cin >> n;
	int x;
	cin >> x;
	int a[100500];
	int b[100500];
	int result = -1;

	for (int i = 0; i < n; i++) {
		int k;cin >> k;
		a[i]=k;
	}

	if (selftest(a,n) == true) {
		result = 0;
	}

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

			if (test((a[i]& x), i, a, n) == true) {
				result = 1;
				break;
			}
			b[i] = (a[i] & x);

		}
	}

	if (result == -1) {
		sort(b, b + n);
		for (int i = 0; i < n; i++) {
			if (b[i] == b[i - 1]) {
				result = 2;
				break;
			}
		}
	}
	cout << result;
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int fun(int a, int b) {
	int l = a;
	int m = b;
	int temp = 0;
	int pow = 1;
	for (int i = 0;; i++) {

		if (l % 2 == 1 && m % 2 == 1) {
			temp += pow;
		}

		if ((l == 0) || (m == 0)) {
			break;
		}

		l = l / 2;
		m = m / 2;
		pow = pow * 2;

	}
	return temp;
}

bool test(int i,int l,vector<int> b) {
	bool temp = false;
	for (unsigned int k = 0; k < b.size(); k++) {
		if (k != l) {
			if (b[k] == i) {
				temp = true;
				break;
			}
		}
	}
	return temp;
}

bool selftest(vector<int>b) {
	int temp = false;
	for (int i = 0; i < b.size(); i++) {
		if (test(b[i], i, b)==true) {
			temp = true;
			break;
		}
		b.pop_back();
	}
	return temp;
}

int main() {
	int n;
	cin >> n;
	int x;
	cin >> x;
	vector<int> a;
	vector<int> b;
	int result = -1;

	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		a.push_back(k);
	}

	for (int i = 0; i < n; i++) {
		if (selftest(a) == true) {
			result = 0;
			break;
		}

	}

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

			if (test(fun(a[i], x), i, a) == true) {
				result = 1;
				break;
			}
			else {
				b.push_back(fun(a[i], x));
			}
		}
	}

	if (result == -1) {
		for (int i = 0; i < n; i++) {
			if (selftest(b)==true) {
				result = 2;
				break;
			}
		}
	}
	cout << result;
	return 0;
}


#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int fun(int a, int b) {
	int l = a;
	int m = b;
	int q;
	int r;
	int temp = 0;
	for (int i = 0;; i++) {
		q = l / pow(2, i);
		r = m / pow(2, i);
		if (q % 2 == 1 && r % 2 == 1) {
			temp += pow(2, i);
			a = a / 2;
			b = b / 2;
		}

		if ((q == 0) || (r == 0)) {
			break;
		}

	}
	return temp;
}

bool test(int i,int l,vector<int> b) {
	bool temp = false;
	for (unsigned int k = 0; k < b.size(); k++) {
		if (k != l) {
			if (b[k] == i) {
				temp = true;
				break;
			}
		}
	}
	return temp;
}

int main() {
	int n;
	cin >> n;
	int x;
	cin >> x;
	vector<int> a;
	vector<int> b;
	int result = -1;

	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		a.push_back(k);
	}

	for (int i = 0; i < n; i++) {
		if (test(a[i], i, a) == true) {
			result = 0;
			break;
		}

	}

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

			if (test(fun(a[i], x), i, a) == true) {
				result = 1;
				break;
			}
			else {
				b.push_back(fun(a[i], x));
			}
		}
	}

	if (result == -1) {
		for (int i = 0; i < n; i++) {
			if (test(b[i],i,b)==true) {
				result = 2;
				break;
			}
		}
	}
	cout << result;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

/*int fun(int a, int b) {
	int l = a;
	int m = b;
	int temp = 0;
	int pow = 1;
	for (int i = 0;; i++) {

		if (l % 2 == 1 && m % 2 == 1) {
			temp += pow;
		}

		if ((l == 0) || (m == 0)) {
			break;
		}

		l = l / 2;
		m = m / 2;
		pow = pow * 2;

	}
	return temp;
}*/

bool test(int i,int l,vector<int> b) {
	bool temp = false;
	for (unsigned int k = 0; k < b.size(); k++) {
		if (k != l) {
			if (b[k] == i) {
				temp = true;
				break;
			}
		}
	}
	return temp;
}

bool selftest(vector<int>b) {
	int temp = false;
	sort(b.begin(), b.end());
	for (int i = 0; i < (b.size()-1);i++) {
		if (b[i]==b[i+1]) {
			temp = true;
			break;
		}
	}
	return temp;
}

int main() {
	int n;
	cin >> n;
	int x;
	cin >> x;
	vector<int> a;
	vector<int> b;
	int result = -1;

	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		a.push_back(k);
	}

	if (selftest(a) == true) {
		result = 0;
	}

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

			if (test((a[i]& x), i, a) == true) {
				result = 1;
				break;
			}
			else {
				b.push_back((a[i] & x));
			}
		}
	}

	if (result == -1) {
			if (selftest(b)==true) {
				result = 2;
			}
	}

	cout << result;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int x;
    cin >> x;
    int arr[n];
    int arrCnt[100001]={0};
    for(int i=0;i<n;i++){
        cin >> arr[i];
        arrCnt[arr[i]]++;
        if(arrCnt[arr[i]]>1){
            cout << "0";
            return 0;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(arrCnt[arr[i]&x]==1 && arr[i]!=arr[i]&x){
            cout << "1";
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        arr[i] = arr[i]&x;
        arrCnt[arr[i]]--;
        arrCnt[arr[i]&x]++;
    }
    for(int i=0;i<n;i++){
        if(arrCnt[arr[i]&x]==1 && arr[i]!=arr[i]&x){
            cout << "2";
            return 0;
        }
    }
    cout << "-1";
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int x;
    cin >> x;
    int arr[n];
    int arrCnt[100001]={0};
    for(int i=0;i<n;i++){
        cin >> arr[i];
        arrCnt[arr[i]]++;
        if(arrCnt[arr[i]]>1){
            cout << "0";
            return 0;
        }
    }
    sort(arr,arr+n);
    int ans=0;
    for(int i=n-1;i>=0;i--){
        arrCnt[arr[i]]--;
        arrCnt[arr[i]&x]++;
        ans++;
        if(arrCnt[arr[i]&x]>1){
            cout << ans;
            return 0;
        }
    }
    cout << "-1";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int x;
    cin >> x;
    int arr[n];
    int arrCnt[100001]={0};
    int Xcnt[x+1] = {0};
    for(int i=0;i<n;i++){
        cin >> arr[i];
        arrCnt[arr[i]]++;
        Xcnt[arr[i]%(x+1)]++;
        if(arrCnt[arr[i]]>1){
            cout << "0";
            return 0;
        }
    }
    for(int i=0;i<=x;i++){
        if(Xcnt[i]>1){
            if(arrCnt[i]>0){
                cout << "1";
            }else{
                cout << "2";
            }
            return 0;
        }
    }
    cout << "-1";
    return 0;
}


#include <iostream>
#include <set>
using namespace std;

int main()
{
    int n,x;
    cin >> n >> x;
    int arr[n];
    set<int> s;
    for(int i=0;i<n;i++){
        cin >> arr[i];
        s.insert(arr[i]);
    }
    if(s.size() < n){
        cout << "0";
        return 0;
    }
    set<int> ns;
    for(int i=0;i<n;i++){
        int nn = arr[i]&x;
        if(nn!=arr[i] && s.find(nn)!=s.end()){
            cout << "1";
            return 0;
        }
        ns.insert(nn);
    }
    if(ns.size() < n){
        cout << "2";
        return 0;
    }
    cout << "-1";
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int x;
    cin >> x;
    int arr[n];
    int arrCnt[100001]={0};
    for(int i=0;i<n;i++){
        cin >> arr[i];
        arrCnt[arr[i]]++;
        if(arrCnt[arr[i]]>1){
            cout << "0";
            return 0;
        }
    }
    sort(arr,arr+n);
    int ans=0;
    for(int i=n-1;i>=0;i--){
        arrCnt[arr[i]]--;
        arrCnt[arr[i]&x]++;
        ans++;
        if(arrCnt[arr[i]&x]>1){
            cout << min(ans,2);
            return 0;
        }
    }
    cout << "-1";
    return 0;
}


#include <iostream>
#include <set>
using namespace std;

int main()
{
    int n,x;
    cin >> n >> x;
    int arr[n];
    set<int> s;
    for(int i=0;i<n;i++){
        cin >> arr[i];
        s.insert(arr[i]);
    }
    if(s.size() < n){
        cout << "0";
        return 0;
    }
    set<int> ns;
    for(int i=0;i<n;i++){
        int nn = arr[i]&x;
        if(nn!=arr[i] && s.find(nn)!=s.end()){
            cout << "1";
            return 0;
        }
        ns.insert(nn);
    }
    if(ns.size() < n){
        cout << "2";
    }
    cout << "-1";
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int x;
    cin >> x;
    int arr[n];
    int arrCnt[100001]={0};
    for(int i=0;i<n;i++){
        cin >> arr[i];
        arrCnt[arr[i]]++;
        if(arrCnt[arr[i]]>1){
            cout << "0";
            return 0;
        }
    }
    sort(arr,arr+n);
    long long int ans=0;
    for(int i=n-1;i>=0;i--){
        arrCnt[arr[i]]--;
        arrCnt[arr[i]&x]++;
        ans++;
        if(arrCnt[arr[i]&x]>1){
            cout << min(ans,2);
            return 0;
        }
    }
    cout << "-1";
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int x;
    cin >> x;
    int arr[n];
    int arrCnt[100001]={0};
    for(int i=0;i<n;i++){
        cin >> arr[i];
        arrCnt[arr[i]]++;
        if(arrCnt[arr[i]]>1){
            cout << "0";
            return 0;
        }
    }
    int ans=0;
    bool arrTest[100001] = {false};
    for(int i=0;i<n;i++){
        arrCnt[arr[i]]--;
        arrCnt[arr[i]&x]++;

        if(arrCnt[arr[i]&x]>1){
            if(!arrTest[arr[i]&x]){
                cout << "1";
            }else{
                cout << "2";
            }
            return 0;
        }
        if(arr[i] != (arr[i]&x))
            arrTest[arr[i]&x]=true;
    }
    cout << "-1";
    return 0;
}


#include <cstdio>
#include <cstdlib>

using namespace std;

int n, x;
int a[100001];

int compare(const void* x, const void* y) {
    return (*(int*)x - *(int*)y);
}

void handleInput() {
    scanf("%d", &n);
    scanf("%d", &x);

    for (int i = 0;i < n;i ++)
        scanf("%d", &a[i]);

}

int binarySearch(int value, int* array, int l, int r) {

    int indexMid;
    do {
        indexMid = (l + r) >> 1;
        if (value < array[indexMid])
            r = indexMid;
        else if (value > array[indexMid])
            l = indexMid + 1;
        if (l == r && a[l] == value) {
            return l;
        }

    } while (l < r);
    return -1;
}

int process() {
    qsort(a, n, sizeof(int), compare);

    for (int i = 0;i < n - 1;i ++) {
        if (a[i] == a[i + 1]) {
            return 0;
        }
    }

    int threshold = 0;
    for (int i = 0;i < n;i ++) {
        if (a[i] > x) {
            threshold = i;
            break;
        }
    }

    if (a[threshold] > x) {
        for (int i = threshold;i < n;i ++) {

            a[i] = a[i] & x;

            if (binarySearch(a[i], a, 0, threshold - 1) > 0) {
                return 1;
            }
        }

        qsort(a, n, sizeof(int), compare);

        for (int i = 0;i < n - 1;i ++) {
            if (a[i] == a[i + 1]) {
                return 2;
            }
        }

        return -1;
    } else {
        return -1;
    }
}

int main() {
    handleInput();
    printf("%d\n", process());

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

int n, x;
vector<int> a;

bool compare(int i, int j) {
    return (i < j);
}

void handleInput() {
    scanf("%d", &n);
    scanf("%d", &x);

    for (int i = 0;i < n;i ++) {
        int temp;
        scanf("%d", &temp);
        a.push_back(temp);
    }

}

int process() {
    sort(a.begin(), a.end(), compare);

    for (int i = 0;i < n - 1;i ++) {
        if (a[i] == a[i + 1]) {
            return 0;
        }
    }

    int threshold = 0;
    for (int i = 0;i < n;i ++) {
        if (a[i] > x) {
            threshold = i;
            break;
        }
    }

    if (a[threshold] > x) {
        for (int i = threshold;i < n;i ++) {

            a[i] = a[i] & x;

            if (binary_search(a.begin(), a.end(), a[i])) {
                return 1;
            }
        }

        sort(a.begin(), a.end(), compare);

        for (int i = 0;i < n - 1;i ++) {
            if (a[i] == a[i + 1]) {
                return 2;
            }
        }

        return -1;
    } else {
        return -1;
    }
}

int main() {
    handleInput();
    printf("%d\n", process());

    return 0;
}


#include <cstdio>
#include <cstdlib>

using namespace std;

int n, x;
int a[100001];

int compare(const void* x, const void* y) {
    return (*(int*)x - *(int*)y);
}

void handleInput() {
    scanf("%d", &n);
    scanf("%d", &x);

    for (int i = 0;i < n;i ++)
        scanf("%d", &a[i]);

}

int binarySearch(int value, int* array, int l, int r) {

    int indexMid;
    do {
        indexMid = (l + r) >> 1;
        if (value < array[indexMid])
            r = indexMid;
        else if (value > array[indexMid])
            l = indexMid + 1;
        else {
            return indexMid;
        }

    } while (l < r);
    if (l == r && a[l] == value)
        return l;
    return -1;
}

int process() {
    qsort(a, n, sizeof(int), compare);

    for (int i = 0;i < n - 1;i ++) {
        if (a[i] == a[i + 1]) {
            return 0;
        }
    }

    int threshold = 0;
    for (int i = 0;i < n;i ++) {
        if (a[i] > x) {
            threshold = i;
            break;
        }
    }

    if (a[threshold] > x) {
        for (int i = threshold;i < n;i ++) {

            a[i] = a[i] & x;

            if (binarySearch(a[i], a, 0, threshold - 1) > 0) {
                return 1;
            }
        }

        qsort(a, n, sizeof(int), compare);

        for (int i = 0;i < n - 1;i ++) {
            if (a[i] == a[i + 1]) {
                return 2;
            }
        }

        return -1;
    } else {
        return -1;
    }
}

int main() {
    handleInput();
    printf("%d\n", process());

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

int n, x;
vector<int> a;

bool compare(int i, int j) {
    return (i < j);
}

void handleInput() {
    scanf("%d", &n);
    scanf("%d", &x);

    for (int i = 0;i < n;i ++) {
        int temp;
        scanf("%d", &temp);
        a.push_back(temp);
    }

}

int process() {
    sort(a.begin(), a.end(), compare);

    for (int i = 0;i < n - 1;i ++) {
        if (a[i] == a[i + 1]) {
            return 0;
        }
    }

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

        int temp = a[i] & x;
        if (a[i] != temp && binary_search(a.begin(), a.end(), temp)) {
            return 1;
        }
    }

    for (int i = 0;i < n;i ++) {
        a[i] = a[i] & x;
    }

    sort(a.begin(), a.end(), compare);

    for (int i = 0;i < n - 1;i ++) {
        if (a[i] == a[i + 1]) {
            return 2;
        }
    }

    return -1;

}

int main() {
    handleInput();
    printf("%d\n", process());

    return 0;
}


#include <cstdio>
#include <cstdlib>

using namespace std;

int n, x;
int a[100001];

int compare(const void* x, const void* y) {
    return (*(int*)x - *(int*)y);
}

void handleInput() {
    scanf("%d", &n);
    scanf("%d", &x);

    for (int i = 0;i < n;i ++)
        scanf("%d", &a[i]);

}

int binarySearch(int value, int* array, int l, int r) {
    int mid = array[(l + r) >> 1];
    while (l != r) {
        if (value < mid) {
            r = (l + r) >> 1;
            binarySearch(value, array, l, r);
        } else if (value > mid) {
            l = ((l + r) >> 1) + 1;
            binarySearch(value, array, l, r);
        } else {
            return (l + r) >> 1;
        }
    }
    if (a[l] == value) {
        return l;
    }
    return -1;
}

int process() {
    qsort(a, n, sizeof(int), compare);

    for (int i = 0;i < n - 1;i ++) {
        if (a[i] == a[i + 1]) {
            return 0;
        }
    }

    int threshold = 0;
    for (int i = 0;i < n;i ++) {
        if (a[i] > x) {
            threshold = i;
            break;
        }
    }

    if (a[threshold] > x) {
        for (int i = threshold;i < n;i ++) {

            a[i] = a[i] & x;

            if (binarySearch(a[i], a, 0, threshold - 1) > 0) {
                return 1;
            }
        }

        qsort(a, n, sizeof(int), compare);

        for (int i = 0;i < n - 1;i ++) {
            if (a[i] == a[i + 1]) {
                return 2;
            }
        }

        return -1;
    } else {
        return -1;
    }
}

int main() {
    handleInput();
    printf("%d\n", process());

    return 0;
}


#include <cstdio>
#include <cstdlib>

using namespace std;

int n, x;
int a[100001];

int compare(const void* x, const void* y) {
    return (*(int*)x - *(int*)y);
}

void handleInput() {
    scanf("%d", &n);
    scanf("%d", &x);

    for (int i = 0;i < n;i ++)
        scanf("%d", &a[i]);

}

int binarySearch(int value, int* array, int l, int r) {

    int indexMid;
    do {
        indexMid = (l + r) >> 1;
        if (value < array[indexMid])
            r = indexMid;
        else if (value > array[indexMid])
            l = indexMid + 1;
        if (l == r && a[l] == value) {
            return l;
        }
    } while (l < r);
    return -1;
}

int process() {
    qsort(a, n, sizeof(int), compare);

    for (int i = 0;i < n - 1;i ++) {
        if (a[i] == a[i + 1]) {
            return 0;
        }
    }

    int threshold = 0;
    for (int i = 0;i < n;i ++) {
        if (a[i] > x) {
            threshold = i;
            break;
        }
    }

    if (a[threshold] > x) {
        for (int i = threshold;i < n;i ++) {

            a[i] = a[i] & x;

            if (binarySearch(a[i], a, 0, threshold - 1) > 0) {
                return 1;
            }
        }

        qsort(a, n, sizeof(int), compare);

        for (int i = 0;i < n - 1;i ++) {
            if (a[i] == a[i + 1]) {
                return 2;
            }
        }

        return -1;
    } else {
        return -1;
    }
}

int main() {
    handleInput();
    printf("%d\n", process());

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

int n, x;
vector<int> a;

bool compare(int i, int j) {
    return (i < j);
}

void handleInput() {
    scanf("%d", &n);
    scanf("%d", &x);

    for (int i = 0;i < n;i ++) {
        int temp;
        scanf("%d", &temp);
        a.push_back(temp);
    }

}

int process() {
    sort(a.begin(), a.end(), compare);

    for (int i = 0;i < n - 1;i ++) {
        if (a[i] == a[i + 1]) {
            return 0;
        }
    }

    int threshold = 0;
    for (int i = 0;i < n;i ++) {
        if (a[i] > x) {
            threshold = i;
            break;
        }
    }

    if (a[threshold] > x) {
        for (int i = threshold;i < n;i ++) {

            a[i] = a[i] & x;

            if (binary_search(a.begin(), a.begin() + threshold, a[i])) {
                return 1;
            }
        }

        sort(a.begin(), a.end(), compare);

        for (int i = 0;i < n - 1;i ++) {
            if (a[i] == a[i + 1]) {
                return 2;
            }
        }

        return -1;
    } else {
        return -1;
    }
}

int main() {
    handleInput();
    printf("%d\n", process());

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p,a,b) for(ll p=a ; p<b ; p++)
#define rap(p,a,b) for(ll p=a ; p<=b ; p++)
#define per(p,a,b) for(ll p=a ; p>=b ; p--)
#define F first
#define S second
using namespace std;

typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector<string> vstr;
typedef pair< ll ,ll > pll;

//see 215div2

int main()
{
    ll t,i,j,k,ans,n,x,y;

    //cin>>t;
    t=1;
    while(t--)
    {
        map<ll,ll> m;
        cin>>n>>x;
        set<ll> s1,s2;
        rep(p,0,n)
        {
            cin>>y;
            m[y]++;
            s1.insert(y);

            if(m[y]>=2)
            {
                cout<<"0";
                return 0;
            }
        }

        ans = 20;
        for(auto it : s1)
        {
            y = it&x;
            if(y!=it)
            {
                if(s1.count(y))
                {
                    ans=min(ans,1LL);
                    break;
                }else if(s2.count(y))
                {
                    ans=min(ans,2LL);
                    break;
                }
            }
            s2.insert(y);

        }

        if(ans==20)cout<<"-1";
        else cout<<ans;
    }

    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p,a,b) for(ll p=a ; p<b ; p++)
#define rap(p,a,b) for(ll p=a ; p<=b ; p++)
#define per(p,a,b) for(ll p=a ; p>=b ; p--)
#define F first
#define S second
using namespace std;

typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector<string> vstr;
typedef pair< ll ,ll > pll;

//see 215div2

int main()
{
    ll t,i,j,k,ans,n,x,y;

    //cin>>t;
    t=1;
    while(t--)
    {
        map<ll,ll> m;
        cin>>n>>x;
        set<ll> s1,s2;
        rep(p,0,n)
        {
            cin>>y;
            m[y]++;
            s1.insert(y);

            if(m[y]>=2)
            {
                cout<<"0";
                return 0;
            }
        }

        ans = 20;
        for(auto it : s1)
        {
            y = it&x;
            if(y!=it)
            {
                if(s1.count(y))
                {
                    ans=min(ans,1LL);
                    //break;
                }else if(s2.count(y))
                {
                    ans=min(ans,2LL);
                    //break;
                }
            }
            s2.insert(y);

        }

        if(ans==20)cout<<"-1";
        else cout<<ans;
    }

    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p,a,b) for(ll p=a ; p<b ; p++)
#define rap(p,a,b) for(ll p=a ; p<=b ; p++)
#define per(p,a,b) for(ll p=a ; p>=b ; p--)
#define F first
#define S second
using namespace std;

typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector<string> vstr;
typedef pair< ll ,ll > pll;

//see 215div2

int main()
{
    ll t,i,j,k,ans,n,x,y;

    //cin>>t;
    t=1;
    while(t--)
    {
        map<ll,ll> m;
        cin>>n>>x;
        set<ll> s;
        rep(p,0,n)
        {
            cin>>y;
            m[y]++;
            s.insert(y);
        }

        ans = -1;
        for(auto it : s)
        {
            if(m[it]>=2)
            {
                ans =0;
                break;
            }

            y = it&x;
            if(y!=it)
            {
                if(s.count(y))
                {
                    ans =1;
                    break;
                }
            }
        }

        cout<<ans;
    }

    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p,a,b) for(ll p=a ; p<b ; p++)
#define rap(p,a,b) for(ll p=a ; p<=b ; p++)
#define per(p,a,b) for(ll p=a ; p>=b ; p--)
#define F first
#define S second
using namespace std;

typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector<string> vstr;
typedef pair< ll ,ll > pll;

//see 215div2

int main()
{
    ll t,i,j,k,ans,n,x,y;

    //cin>>t;
    t=1;
    while(t--)
    {
        map<ll,ll> m;
        cin>>n>>x;
        set<ll> s;
        rep(p,0,n)
        {
            cin>>y;
            m[y]++;
            s.insert(y);

            if(m[y]>=2)
            {
                cout<<"0";
                return 0;
            }
        }

        ans = -1;
        for(auto it : s)
        {
            y = it&x;
            if(y==it)
            {
                if(m[y] && !s.count(y))
                {
                    ans =2;
                    break;
                }
            }
            else
            {
                if(m[y] && !s.count(y))
                {
                    ans =2;
                    break;
                }
                else if(s.count(y))
                {
                    ans = 1;
                    break;
                }
            }

        }

        cout<<ans;
    }

    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p,a,b) for(ll p=a ; p<b ; p++)
#define rap(p,a,b) for(ll p=a ; p<=b ; p++)
#define per(p,a,b) for(ll p=a ; p>=b ; p--)
#define F first
#define S second
using namespace std;

typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector<string> vstr;
typedef pair< ll ,ll > pll;

//see 215div2

int main()
{
    ll t,i,j,k,ans,n,x,y;

    //cin>>t;
    t=1;
    while(t--)
    {
        map<ll,ll> m;
        cin>>n>>x;
        set<ll> s1,s2;
        rep(p,0,n)
        {
            cin>>y;
            m[y]++;
            s1.insert(y);

            if(m[y]>=2)
            {
                cout<<"0";
                return 0;
            }
        }

        ans = -1;
        for(auto it : s1)
        {
            y = it&x;
            if(y!=it)
            {
                if(s1.count(y))
                {
                    ans=1;
                    break;
                }else if(s2.count(y))
                {
                    ans=2;
                    break;
                }
            }
            s2.insert(y);

        }

        cout<<ans;
    }

    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p,a,b) for(ll p=a ; p<b ; p++)
#define rap(p,a,b) for(ll p=a ; p<=b ; p++)
#define per(p,a,b) for(ll p=a ; p>=b ; p--)
#define F first
#define S second
using namespace std;

typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector<string> vstr;
typedef pair< ll ,ll > pll;

//see 215div2

int main()
{
    ll t,i,j,k,ans,n,x,y;

    //cin>>t;
    t=1;
    while(t--)
    {
        map<ll,ll> m;
        cin>>n>>x;
        set<ll> s;
        rep(p,0,n)
        {
            cin>>y;
            m[y]++;
            s.insert(y);

            if(m[y]>=2)
            {
                cout<<"0";
                return 0;
            }
        }

        ans = -1;
        for(auto it : s)
        {
            y = it&x;
            if(y==it)
            {
                if(m[y] && !s.count(y))
                {
                    ans =2;
                    break;
                }
            }
            else
            {
                if(m[y] && !s.count(y))
                {
                    ans =2;
                    break;
                }
                else if(s.count(y))
                {
                    ans = 1;
                    break;
                }
            }
            m[y]++;

        }

        cout<<ans;
    }

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[10000000];
map<ll,ll>m;
bool check(int ai,int x)
{
    while(x)
    {
        if((x&1)&&!(ai&1))
            return false;
        x>>=1;
        ai>>=1;

    }
    return true;
}

int main()
{
    ll n,x,c=0;
cin>>n>>x;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(m[a[i]]==1)
        {
            cout<<0;
            return 0;
        }
        m[a[i]]=1;
        if(check(a[i],x))
            c++;
    }

if(m[x]==1&&c>1)
    cout<<1;
else if(c>=2)
    cout<<2;
else
    cout<<-1;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[10000000],a2[1000005];
map<ll,ll>m;
bool check(int ai,int x)
{
    while(x)
    {
        if((x&1)&&!(ai&1))
            return false;
        x>>=1;
        ai>>=1;

    }
    return true;
}

int main()
{
    ll n,x,c=0,f2=0;
cin>>n>>x;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(m[a[i]]==1)
        {
            cout<<0;
            return 0;
        }
        m[a[i]]=1;
     c=(x&a[i]);
     a2[c]++;
if(a2[c]==2)
{
    f2=1;
}
    }

if(a2[x]>=2)
    cout<<1;
else if(f2)
    cout<<2;
else
    cout<<-1;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[10000000];
map<ll,ll>m;
bool check(int ai,int x)
{
    while(x)
    {
        if((x&1)&&!(ai&1))
            return false;
        x>>=1;
        ai>>=1;

    }
    return true;
}

int main()
{
    ll n,x,c=0;
cin>>n>>x;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(m[a[i]]==1)
        {
            cout<<0;
            return 0;
        }
        m[a[i]]=1;
        if(check(a[i],x))
            c++;
    }

if(m[x]==1&&c>=1)
    cout<<1;
else if(c>=2)
    cout<<2;
else
    cout<<-1;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[10000000],a2[1000005];
map<ll,ll>m;
bool check(int ai,int x)
{
    while(x)
    {
        if((x&1)&&!(ai&1))
            return false;
        x>>=1;
        ai>>=1;

    }
    return true;
}

int main()
{
    ll n,x,c=0,f2=0;
cin>>n>>x;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(m[a[i]]==1)
        {
            cout<<0;
            return 0;
        }
        m[a[i]]=1;
     c=(x&a[i]);
     a2[c]++;
if(a2[c]==2)
{
    f2=1;
}
    }

if(a2[x]>=2&&m[x])
    cout<<1;
else if(f2)
    cout<<2;
else
    cout<<-1;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[10000000],a2[1000005];
map<ll,ll>m;
bool check(int ai,int x)
{
    while(x)
    {
        if((x&1)&&!(ai&1))
            return false;
        x>>=1;
        ai>>=1;

    }
    return true;
}

int main()
{
    ll n,x,c=0,f2=0;
cin>>n>>x;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(m[a[i]]==1)
        {
            cout<<0;
            return 0;
        }
        m[a[i]]=1;
     c=(x&a[i]);
     a2[c]++;
if(a2[c]==2)
{
    f2=1;
}
    }

if(m[x]==1&&a2[x]>1)
    cout<<1;
else if(f2)
    cout<<2;
else
    cout<<-1;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ex[10000000],a2[1000005],k[100000];
int main()
{
    ll n,x,c=0,f2=0;
    cin>>n>>x;
    for(int i=0; i<n; i++)
    {
        cin>>k[i];
        ex[k[i]]++;
        if(ex[k[i]]==2)
        {
            cout<<0;
            return 0;
        }
    }
    for(int i=0;i<n;i++)
    {
          c=(x&k[i]);

        if(a2[c]&&ex[c])
        {
            cout<<1;
            return 0;
        }
         a2[c]++;
            if(a2[c]==2)
        {
            f2=1;
        }

    }

    if(f2)
        cout<<2;
    else
        cout<<-1;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[10000000],a2[1000005];
map<ll,ll>m;
bool check(int ai,int x)
{
    while(x)
    {
        if((x&1)&&!(ai&1))
            return false;
        x>>=1;
        ai>>=1;

    }
    return true;
}

int main()
{
    ll n,x,c=0,f2=0;
cin>>n>>x;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(m[a[i]]==1)
        {
            cout<<0;
            return 0;
        }
        m[a[i]]=1;
     c=(x&a[i]);
     a2[c]++;
if(a2[c]==2)
{
    f2=1;
}
    }

if(m[x]==1&&a2[x])
    cout<<1;
else if(f2)
    cout<<2;
else
    cout<<-1;

    return 0;
}


        #include <bits/stdc++.h>
        #define ll long long
        #define pb push_back
        #define mp make_pair
        #define rep(i,a,b) for(int i=a;i<b;i++)
        using namespace std;

        int main() {
        	int t=1;
        	//cin>>t;
        	while(t--){
        		int n,x;cin>>n>>x;
        		vector<int>a;
        		a.clear();
        		rep(i,0,n) {
        			int temp;cin>>temp;
        			a.push_back(temp);
        		}
        		sort(a.begin(),a.end());
        		bool rep=false;
        		rep(i,0,n-1){
        			if(a[i]==a[i+1]){
        				rep=true;break;
        			}
        		}
        		if(rep) cout<<0<<endl;
    			else if(*lower_bound(a.begin(),a.end(),x)==x && lower_bound(a.begin(),a.end(),x)+1<a.end()){
    				cout<<1<<endl;
    			}else if(upper_bound(a.begin(),a.end(),x)+1<a.end()){
    				cout<<2<<endl;
    			}
    			else cout<<-1<<endl;
    		}
        	return 0;
        }


                #include <bits/stdc++.h>
                #define ll long long
                #define pb push_back
                #define mp make_pair
                #define rep(i,a,b) for(int i=a;i<b;i++)
                using namespace std;

                int main() {
                	int t=1;
                	//cin>>t;
                	while(t--){
                		int n,x;cin>>n>>x;
                		vector<int>a,b;
                		a.clear();
                		rep(i,0,n) {
                			int temp;cin>>temp;
                			a.push_back(temp);
                			b.push_back(temp&x);
                		}
                		sort(a.begin(),a.end());
                		sort(b.begin(),b.end());
                		bool rep=false;
                		rep(i,0,n-1){
                			if(a[i]==a[i+1]){
                				rep=true;break;
                			}
                		}
                		bool rep2=false;
                		rep(i,0,n-1){
                			if(b[i]==b[i+1]){
                				rep2=true;break;
                			}
                		}
                		if(rep) cout<<0<<endl;
                		else if(!rep2) cout<<-1<<endl;
            			else if(*lower_bound(a.begin(),a.end(),x)==x && lower_bound(a.begin(),a.end(),x)+2<a.end()){
            				cout<<1<<endl;
            			}else if(upper_bound(a.begin(),a.end(),x)+1<a.end()){
            				cout<<2<<endl;
            			}
            			else cout<<-1<<endl;
            		}
                	return 0;
                }


                    #include <bits/stdc++.h>
                    #define ll long long
                    #define pb push_back
                    #define mp make_pair
                    #define rep(i,a,b) for(int i=a;i<b;i++)
                    using namespace std;

                    int main() {
                    	int t=1;
                    	//cin>>t;
                    	while(t--){
                    		int n,x;cin>>n>>x;
                    		vector<int>a,b;
                    		a.clear();
                    		rep(i,0,n) {
                    			int temp;cin>>temp;
                    			a.push_back(temp);
                    			b.push_back(temp&x);
                    		}
                    		sort(a.begin(),a.end());
                    		sort(b.begin(),b.end());
                    		bool rep=false;
                    		rep(i,0,n-1){
                    			if(a[i]==a[i+1]){
                    				rep=true;break;
                    			}
                    		}
                    		bool rep2=false;
                    		rep(i,0,n-1){
                    			if(b[i]==b[i+1]){
                    				rep2=true;break;
                    			}
                    		}
                    		if(rep) cout<<0<<endl;
                    		else if(!rep2) cout<<-1<<endl;
                			else if(*lower_bound(a.begin(),a.end(),x)==x && lower_bound(a.begin(),a.end(),x)+1<a.end()){
                				cout<<1<<endl;
                			}else if(lower_bound(a.begin(),a.end(),x)+1<a.end()){
                				cout<<2<<endl;
                			}
                			else cout<<-1<<endl;
                		}
                    	return 0;
                    }


    #include <bits/stdc++.h>
    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define rep(i,a,b) for(int i=a;i<b;i++)
    using namespace std;

    int main() {
    	int t=1;
    	//cin>>t;
    	while(t--){
    		int n,x;cin>>n>>x;
    		vector<int>a;
    		a.clear();
    		rep(i,0,n) {
    			int temp;cin>>temp;
    			a.push_back(temp);
    		}
    		sort(a.begin(),a.end());
    		bool rep=false;
    		rep(i,0,n-1){
    			if(a[i]==a[i+1]){
    				rep=true;break;
    			}
    		}
    		if(rep) cout<<0<<endl;
			else if(*lower_bound(a.begin(),a.end(),x)==x && upper_bound(a.begin(),a.end(),x)!=a.end()){
				cout<<1<<endl;
			}else if(upper_bound(a.begin(),a.end(),x)+1<a.end()){
				cout<<2<<endl;
			}
			else cout<<-1<<endl;
		}
    	return 0;
    }


        #include <bits/stdc++.h>
        #define ll long long
        #define pb push_back
        #define mp make_pair
        #define rep(i,a,b) for(int i=a;i<b;i++)
        using namespace std;

        int main() {
        	int t=1;
        //	cin>>t;
        	while(t--){
        		int n,x;cin>>n>>x;
        		vector<int>a;
        		a.clear();
        		rep(i,0,n) {
        			int temp;cin>>temp;
        			a.push_back(temp);
        		}
        		sort(a.begin(),a.end());
            	vector<int>b;
        		rep(i,0,n){
        			b.push_back(a[i]&x);
        		}
           		sort(b.begin(),b.end());
        		bool rep=false;
        		rep(i,0,n-1){
        			if(a[i]==a[i+1] || b[i]==b[i+1]){
        				rep=true;break;
        			}
        		}
        		if(rep) {
        			cout<<0<<endl;
        			continue;
        		}

    			else if(*lower_bound(a.begin(),a.end(),x)==x && lower_bound(a.begin(),a.end(),x)+1<a.end()){
    				cout<<1<<endl;
    			}else if(upper_bound(a.begin(),a.end(),x)+1<a.end()){
    				cout<<2<<endl;
    			}else{
    				cout<<-1<<endl;
    			}
    		}
        	return 0;
        }


        #include <bits/stdc++.h>
        #define ll long long
        #define pb push_back
        #define mp make_pair
        #define rep(i,a,b) for(int i=a;i<b;i++)
        using namespace std;

        int main() {
        	int t=1;
        	//cin>>t;
        	while(t--){
        		int n,x;cin>>n>>x;
        		vector<int>a;
        		a.clear();
        		rep(i,0,n) {
        			int temp;cin>>temp;
        			a.push_back(temp);
        		}
        		sort(a.begin(),a.end());
        		bool rep=false;
        		rep(i,0,n-1){
        			if(a[i]==a[i+1]){
        				rep=true;break;
        			}
        		}
        		if(rep) cout<<0<<endl;
        		else if(lower_bound(a.begin(),a.end(),x)+2<a.end()) cout<<-1<<endl;
    			else if(*lower_bound(a.begin(),a.end(),x)==x && lower_bound(a.begin(),a.end(),x)+1<a.end()){
    				cout<<1<<endl;
    			}else if(upper_bound(a.begin(),a.end(),x)+1<a.end()){
    				cout<<2<<endl;
    			}
    			else cout<<-1<<endl;
    		}
        	return 0;
        }


            #include <bits/stdc++.h>
            #define ll long long
            #define pb push_back
            #define mp make_pair
            #define rep(i,a,b) for(int i=a;i<b;i++)
            using namespace std;

            int main() {
            	int t=1;
            	//cin>>t;
            	while(t--){
            		int n,x;cin>>n>>x;
            		vector<int>a,b;
            		a.clear();
            		rep(i,0,n) {
            			int temp;cin>>temp;
            			a.push_back(temp);
            			b.push_back(temp&x);
            		}
            		sort(a.begin(),a.end());
            		sort(b.begin(),b.end());
            		bool rep=false;
            		rep(i,0,n-1){
            			if(a[i]==a[i+1]){
            				rep=true;break;
            			}
            		}
            		bool rep2=false;
            		rep(i,0,n-1){
            			if(b[i]==b[i+1]){
            				rep2=true;break;
            			}
            		}
            		if(rep) cout<<0<<endl;
            		else if(!rep2) cout<<-1<<endl;
        			else if(*lower_bound(a.begin(),a.end(),x)==x && lower_bound(a.begin(),a.end(),x)+1<a.end()){
        				cout<<1<<endl;
        			}else if(upper_bound(a.begin(),a.end(),x)+1<a.end()){
        				cout<<2<<endl;
        			}
        			else cout<<-1<<endl;
        		}
            	return 0;
            }


        #include <bits/stdc++.h>
        #define ll long long
        #define pb push_back
        #define mp make_pair
        #define rep(i,a,b) for(int i=a;i<b;i++)
        using namespace std;

        int main() {
        	int n,x;
        	cin>>n>>x;
        	int a[n];
        	vector<int>fre;
        	rep(i,0,n){
        		cin>>a[i];
        		fre[a[i]]++;
        	}
        	if(sizeof(fre)!=n){
        		cout<<0<<endl;
        		return 0;
        	}
        	rep(i,0,n){
        		if(a[i]!=a[i]&x && fre.count(a[i]&x)){
        			cout<<1<<endl;
        			return 0;
        		}
        	}
        	fre.clear();
        	rep(i,0,n) fre[a[i]&x]++;
        	if(sizeof(fre)!=n) cout<<2<<endl;
        	else cout<<-1<<endl;
        	return 0;
        }


        #include <bits/stdc++.h>
        #define ll long long
        #define pb push_back
        #define mp make_pair
        #define rep(i,a,b) for(int i=a;i<b;i++)
        using namespace std;
        vector<int>fre;
        int main() {
        	int n,x;
        	cin>>n>>x;
        	int a[n];
            map<int,int>fre;
        	rep(i,0,n){
        		cin>>a[i];
        		fre[a[i]]+=1;
        	}
        	if(fre.size()!=n){
        		cout<<0<<endl;
        		return 0;
        	}
        	rep(i,0,n){
        		if(a[i]!=(a[i]&x) && fre.count((a[i]&x))){
        			cout<<1<<endl;
        			return 0;
        		}
        	}
        	fre.clear();
        	rep(i,0,n) fre[a[i]&x]++;
        	if(fre.size()!=n) cout<<2<<endl;
        	else cout<<-1<<endl;
        	return 0;
        }


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;

int main() {
	int t=1;
	//cin>>t;
	while(t--){
		int n,x;cin>>n>>x;int a[n];
		set<int>s;
		rep(i,0,n) {
			cin>>a[i];
		}
		int ans=100;
		rep(i,0,n){
			if(s.find(a[i])!=s.end()){
				ans=0;
				break;
			} else if(s.find(a[i]&x)!=s.end()){
				ans=min(ans,1);
			}
			s.insert(a[i]);
			s.insert(a[i]&x);
		}
		if(ans==100) cout<<-1<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}


        #include <bits/stdc++.h>
        #define ll long long
        #define pb push_back
        #define mp make_pair
        #define rep(i,a,b) for(int i=a;i<b;i++)
        using namespace std;

        int main() {
        	int t=1;
        	cin>>t;
        	while(t--){
        		int n,x;cin>>n>>x;
        		vector<int>a;
        		a.clear();
        		rep(i,0,n) {
        			int temp;cin>>temp;
        			a.push_back(temp);
        		}
        		sort(a.begin(),a.end());
        		bool rep=false;
        		rep(i,0,n-1){
        			if(a[i]==a[i+1]){
        				rep=true;break;
        			}
        		}
        		if(rep) cout<<0<<endl;
    			else if(*lower_bound(a.begin(),a.end(),x)==x && lower_bound(a.begin(),a.end(),x)+1<a.end()){
    				cout<<1<<endl;
    			}else if(upper_bound(a.begin(),a.end(),x)+1<a.end()){
    				cout<<2<<endl;
    			}
    			else cout<<-1<<endl;
    		}
        	return 0;
        }


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;

int main() {
	int t=1;
	//cin>>t;
	while(t--){
		int n,x;cin>>n>>x;int a[n];
		set<int>s;
		rep(i,0,n) {
			cin>>a[i];
		}
		int ans=100;
		rep(i,0,n){
			if(s.find(a[i])!=s.end()){
				ans=0;
				break;
			} else if(s.find(a[i]&x)!=s.end()){
				ans=min(ans,1);
			}
			s.insert(a[i]);
		}
		if(ans==100) cout<<-1<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main(){
    int n,x;
    cin>>n>>x;
    for(int i=1;i<=n;i++){
        int a,b;
        cin>>a;
        mp[a]++;
    }
    for(auto i:mp){
        if(i.second>=2){
            cout<<0<<endl;
             return 0;
        }

    }
    if(mp[x]==1){
        cout<<1<<endl;
        return 0;
    }
    int flag=0;
    for(auto i:mp){
      int h=i.first&x;
      if(mp[h]==1&&h!=i.first){
        cout<<1<<endl;
        return 0;
      }
    }
    map<int,int>mp1;
    for(auto i:mp){
        int h=i.first&x;
        mp1[h]++;
    }
    for(auto i:mp1){
        if(i.second>=2){
            cout<<2<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main(){
    int n,x;
    cin>>n>>x;
    for(int i=1;i<=n;i++){
        int a,b;
        cin>>a;
        mp[a]++;
    }
    if((x+1)&x==0&&!mp.count(x))
	{
		printf("0\n");
		return 0;
	}
    for(auto i:mp){
        if(i.second>=2){
            cout<<0<<endl;
             return 0;
        }

    }

    int flag=0;
    for(auto i:mp){
      int h=i.first&x;
      if(mp[h]==1&&h!=i.first){
        cout<<1<<endl;
        return 0;
      }
    }
    map<int,int>mp1;
    for(auto i:mp){
        int h=i.first&x;
        mp1[h]++;
    }
    for(auto i:mp1){
        if(i.second>=2){
            cout<<2<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;

}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
#include <algorithm>
using namespace std;
#define maxn 100005
int n,x,num[maxn];
map<int,int> p;
int main()
{

	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&num[i]);
		if(!p.count(num[i]))
		p[num[i]]++;
		else
		{
			printf("0\n");
			return 0;
		}
	}
	if((x+1)&x==0&&!p.count(x))
	{
		printf("0\n");
		return 0;
	}

	for(int i=1;i<=n;i++)
	{
		int t=x&num[i];
		if(p.count(t))
		{
			printf("%d\n",1);
			return 0;
		}
	}
	map<int,int> mp;
	for(int i=1;i<=n;++i)
	{
		num[i]=x&num[i];
		mp[num[i]]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(mp.count(num[i]))
		{
			printf("%d\n",2);
			return 0;
		}
	}

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main(){
    int n,x;
    cin>>n>>x;
    for(int i=1;i<=n;i++){
        int a,b;
        cin>>a;
        mp[a]++;
    }
    if((x+1)&x==0&&!mp.count(x))
	{
		printf("-1\n");
		return 0;
	}
    for(auto i:mp){
        if(i.second>=2){
            cout<<0<<endl;
             return 0;
        }

    }

    for(auto i:mp){
      int h=i.first&x;
      if(mp[h]==1&&h!=i.first){
        cout<<1<<endl;
        return 0;
      }
    }
    map<int,int>mp1;
    for(auto i:mp){
        int h=i.first&x;
        mp1[h]++;
    }
    for(auto i:mp1){
        if(i.second>=2){
            cout<<2<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;

}