#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 BitwiseAnd { public:
	vector<long long> lexSmallest(vector<long long> subset, int N)
	{
		vector<LL> FAIL;

		// precheck
		for(int i=0; i<subset.size(); ++i)
		for(int j=i+1; j<subset.size(); ++j)
			if((subset[i]&subset[j])==0)
				return FAIL;
		for(int i=0; i<subset.size(); ++i)
		for(int j=i+1; j<subset.size(); ++j)
		for(int k=j+1; k<subset.size(); ++k)
			if((subset[i]&subset[j]&subset[k])!=0)
				return FAIL;

		vector<LL> ans = subset;

		LL rest = (1LL<<60)-1;
		vector<LL> leftbits = subset;
		for(int i=0; i<subset.size(); ++i)
		{
			rest &= ~subset[i];
			for(int k=0; k<leftbits.size(); ++k) if(k!=i)
				leftbits[k] &= ~ subset[i];
		}

		while(leftbits.size() < N)
		{
			LL v = 0;
			for(int i=0; i<leftbits.size(); ++i)
			{
				if(leftbits[i] == 0)
					return FAIL;
				LL least = 1;
				while((leftbits[i] & least)==0)
					least <<= 1;
				leftbits[i] &= ~least;
				v |= least;
			}

			LL restv = 0;
			int needbits = (N - leftbits.size() - 1);
			while(needbits--) {
				if(rest == 0)
					return FAIL;
				LL least = 1;
				while((rest & least)==0)
					least <<= 1;
				rest &= ~least;
				restv |= least;
			}

			leftbits.push_back(restv);
			ans.push_back(v | restv);
		}

		sort(ans.begin(), ans.end());
		return ans;
	}
};

// 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 vector<long long>& Expected, const vector<long long>& 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(_, BitwiseAnd().lexSmallest(subset, N));}
int main(){

CASE(0)
	long long subset_[] = {14, 20};
	  vector<long long> subset(subset_, subset_+sizeof(subset_)/sizeof(*subset_)); 
	int N = 3; 
	long long __[] = {14, 18, 20 };
	  vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	long long subset_[] = {11, 17, 20};
	  vector<long long> subset(subset_, subset_+sizeof(subset_)/sizeof(*subset_)); 
	int N = 4; 
	vector<long long> _; 
END
CASE(2)
	long long subset_[] = {99, 157};
	  vector<long long> subset(subset_, subset_+sizeof(subset_)/sizeof(*subset_)); 
	int N = 4; 
	long long __[] = {99, 157, 262, 296 };
	  vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(3)
	long long subset_[] = {1152921504606846975};
	  vector<long long> subset(subset_, subset_+sizeof(subset_)/sizeof(*subset_)); 
	int N = 3; 
	vector<long long> _; 
END
CASE(4)
	vector<long long> subset; 
	int N = 5; 
	long long __[] = {15, 113, 402, 676, 840 };
	  vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(5)
	long long subset_[] = {1, 3, 5, 7, 9, 11};
	  vector<long long> subset(subset_, subset_+sizeof(subset_)/sizeof(*subset_)); 
	int N = 6; 
	vector<long long> _; 
END
CASE(6)
    long long subset_[] = {(1LL<<60)-1>>50<<50};
	  vector<long long> subset(subset_, subset_+sizeof(subset_)/sizeof(*subset_)); 
	int N = 11;
    vector<long long> _;
END
/*
CASE(7)
	long long subset_[] = ;
	  vector<long long> subset(subset_, subset_+sizeof(subset_)/sizeof(*subset_)); 
	int N = ; 
	long long __[] = ;
	  vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 
END
*/
}
// END CUT HERE
