#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class ORSolitaire { public:
	int getMinimum(vector <int> numbers, int goal)
	{
		vector<int> n2;
		for(int u: numbers)
			if((goal&u) == u)
				n2.push_back(u);
		numbers.swap(n2);

		int best = 9999999;
		for(int v=1; v<=goal; v<<=1) if(goal&v) {
			int cnt = 0;
			for(int u: numbers)
				if(u&v)
					++cnt;
			best = min(best, cnt);
		}
		return best;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, ORSolitaire().getMinimum(numbers, goal));}
int main(){

CASE(0)
	int numbers_[] = {1, 2, 4};
	  vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_)); 
	int goal = 7; 
	int _ = 1; 
END
CASE(1)
	int numbers_[] = {1, 2, 4, 7, 8};
	  vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_)); 
	int goal = 7; 
	int _ = 2; 
END
CASE(2)
	int numbers_[] = {12571295, 2174218, 2015120};
	  vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_)); 
	int goal = 1; 
	int _ = 0; 
END
CASE(3)
	int numbers_[] = {5,2,4,52,62,9,8,3,1,11,6};
	  vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_)); 
	int goal = 11; 
	int _ = 3; 
END
CASE(4)
	int numbers_[] = {503, 505, 152, 435, 491, 512, 1023, 355, 510, 500, 502, 255, 63, 508, 509, 511, 60, 250, 254, 346};
	  vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_)); 
	int goal = 510; 
	int _ = 5; 
END
CASE(5)
	int numbers_[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50};
	  vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_)); 
	int goal = 63; 
	int _ = 19;
END
/*
CASE(6)
	int numbers_[] = ;
	  vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_)); 
	int goal = ; 
	int _ = ; 
END
*/
}
// END CUT HERE
