/*
 *    J1K7_7
 *
 *    You can use my contents on a Creative Commons - Attribution 4.0 International - CC BY 4.0 License.  XD 
 *    - JASKAMAL KAINTH
 */
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <cassert>
#include <list>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <limits>
using namespace std;
typedef long long          ll;
typedef unsigned long long ull;
typedef long double        ld;
typedef pair<int,int>      pii;
typedef pair<ll,ll>        pll;
typedef vector<int>        vi;
typedef vector<long long>  vll;
#define left(x) 		   (x << 1)
#define right(x) 		   (x << 1) + 1
#define mid(l, r) 	       ((l + r) >> 1)
#define mp                 make_pair
#define pb                 push_back
#define all(a)             a.begin(),a.end()
#define debug(x)	       {cerr <<#x<<" = " <<x<<"\n"; }
#define debug2(x, y)       {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<"\n";}
#define debug3(x, y, z)    {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<"\n";}
#define debug4(x, y, z, w) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<", "<<#w << " = " <<w <<"\n";}
#define ss                 second
#define ff                 first
#define m0(x) 		       memset(x,0,sizeof(x))

const int mod=1e9+7;

template<class T> inline T gcd(T a,T b){ll t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
template<class T> inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<typename T, typename S> T expo(T b, S e, const T &m){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b)%m, e>>1, m): (b*expo((b*b)%m, e>>1, m))%m;}
template<typename T> T modinv(T a) { return expo(a, mod-2, mod); }

inline int nextint(){ int x; scanf("%d",&x); return x; }
inline ll nextll(){ ll x; scanf("%lld",&x); return x; }

const ll  mx_ll   = numeric_limits<ll> :: max();
const int mx_int  = numeric_limits<int> :: max();

const long double PI = (long double)(3.1415926535897932384626433832795);

#define gc getchar
template <typename T> void scanint(T &x) {
	T c = gc(); while(((c < 48) || (c > 57)) && (c!='-')) c = gc();
	bool neg = false; if(c == '-') neg = true; x = 0; for(;c < 48 || c > 57;c=gc());
	for(;c > 47 && c < 58;c=gc())	x = (x*10) + (c - 48); if(neg)	x = -x;
}

const int maxn = 41;
int n , k; 
ll inp[maxn];

ll xorit(ll x, ll y) 
{
	ll ans = 0, mul = 1;
	for (int i = 0; i < 10; ++i)
	{
		int t = x/10;
		t *= 10;
		int dig1 = x - t;

		t = y/10;
		t *= 10;
		int dig2 = y - t;

		int dig = dig1 + dig2;
		if(dig >= 10)
			dig -= 10;
		ans = ans + 1ll * dig * mul;
		mul = mul * 10;
		x /= 10;
		y /= 10;
	}
	return ans;
}

int trie[21][1<<19][10];
int sz[21];

string convert(ll a)
{
	string ret;
	for (int i = 0; i < 10; ++i) 
	{
		int t = a/10;
		t *= 10;
		int dig = a - t;
		a /= 10;
		ret += dig + '0';
	}
	return ret;
}

inline void insert(ll num,int id)
{
	int node = 0;
	string a = convert(num);
	for(int i = 0; i < 10; i++)
	{
		int b = a[9-i]-'0';
		if(trie[id][node][b] == -1)
		{
			trie[id][node][b] = sz[id]++;
		}
		node = trie[id][node][b];
	}
}
inline ll query(ll num,int id)
{

	string a = convert(num);
	int node = 0;
	ll ans = 0ll;
	for(int i = 0; i < 10; i++)
	{
		int b = a[9-i]-'0';
		int found = 0;
		for(int j = 9-b; j >= 0; j--)
		{
			if(trie[id][node][j] != -1)
			{
				found = 1;
				ans = ans * 10 + (j+b);
				node = trie[id][node][j];
				break;
			}
		}
		if(found)
			continue;
		else
		{
			for(int j = 9; j > 9-b; j--)  
			{
				if(trie[id][node][j] != -1)
				{
					found = 1;
					ans = ans * 10 + (j+b-10);
					node = trie[id][node][j];
					break;
				}
			}
		}

	}
	return ans;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i = 0; i < 21; i++)
		sz[i] = 1;
	for(int i = 0; i < 21; i++)
	{
		for(int j = 0; j < (1<<19); j++)
		{
			for(int k = 0; k < 10; k++)
			{
				trie[i][j][k] = -1;  
			}
		}
	}
	for(int i = 0; i < n; i++)
		scanf("%lld",&inp[i]);

	if(k == 1)
	{
		cout << *max_element(inp,inp+n) << "\n";  
		return 0;
	}
	int nhalf = n/2;
	int pow2[21];
	for(int i = 0; i < 21; i++)
		pow2[i] = 1<<i;

	int lim = (1<<nhalf);
	for(int mask = 0; mask < lim; mask++)
	{
		int szmask = __builtin_popcount(mask);
		if( szmask > k ) continue;
		ll num = 0;
		int size_subset = 0;
		for(int i = 0; i < nhalf; i++)
			if(mask & pow2[i])
			{
				num = xorit(num,inp[i]);  
				size_subset++;
			}
		insert(num,size_subset);
	}
	ll ans = -1;
	lim = (1<<(n-nhalf));
	for(int mask = 0; mask < lim; mask++)
	{
		int szmask = __builtin_popcount(mask);
		if( (szmask > k) || sz[k-szmask] == 1 ) continue;

		int size_subset = 0;
		ll num = 0ll;
		for(int i = 0; i < (n-nhalf); i++)
			if(mask & pow2[i])
			{
				num = xorit(num,inp[i+nhalf]);  
				size_subset++;
			}
		if(k >= size_subset && k - size_subset <= nhalf)
		{
			ans = max( ans , query(num,k-size_subset));
		}
	}
	printf("%lld\n",ans);
	return 0;
}



