#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <map>
#include <set>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

vector<ll> A;

ll calc(ll N, ll sep)
{
    ll ret = 0;
    //vector<ll> v;
    ll OR = 0;
    bool f = false;
    for(ll i = 0;i < N;i++)
    {
        OR |= A[i];
        f = true;
        if(sep & (1LL<<i))
        {
            ret ^= OR;
            OR = 0LL;
            f = false;
        }
    }
    if(f)
    {
        ret ^= OR;
    }
    return ret;
}

int main()
{
    ll N;
    cin >> N;
    A.resize(N);
    for(ll i = 0;i < N;i++)
    {
        cin >> A[i];
    }

    ll sep;
    ll lim = 1<<(N-1LL);
    ll ans = 1e15;
    for(sep=0;sep<lim;sep++)
    {
        ll ret = calc(N, sep);
        //cout << "ret = " << ret << " sep = " << sep << endl;
        ans = min(ans, ret);
    }
    cout << ans << endl;
    return 0;
}
// Problem: B - Mex Boxes
// Contest: AtCoder - KEYENCE Programming Contest 2021
// URL: https://atcoder.jp/contests/keyence2021/tasks/keyence2021_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

// Problem: A - Two Sequences 2
// Contest: AtCoder - KEYENCE Programming Contest 2021
// URL: https://atcoder.jp/contests/keyence2021/tasks/keyence2021_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define int long long
using namespace std;
#ifndef use_ios11
#define use_ios11
using namespace std;
struct ins{
    int ans;
    ins(){ans=1;}
#define endl '\n'
    void read(){}
    void read1(char &s){
        char c=getchar();
        for(;!isprint(c)||c==' '||c=='\n'||c=='\t';c=getchar());
        s=c;
        if(c==EOF)ans=0;
    }
    void read1(string &s){
        s="";
        char c=getchar();
        for(;!isprint(c)||c==' '||c=='\n'||c=='\t';c=getchar());
        for (;isprint(c)&&c!=' '&&c!='\n'&&c!='\t';c=getchar())s+=c;
        if(c==EOF)ans=0;
    }
    template<typename T>void read1(T &n){
        T x=0;int f=1;char c=getchar();
        for(;!isdigit(c);c=getchar()){
            if(c=='-')f=-1;
            if(c==EOF){ans=0;return;}
        }
        for(;isdigit(c);c=getchar())x=x*10+c-48;
        n=x*f;
        if(c==EOF)ans=0;
        if(c!='.')return;
        T l=0.1;
        while((c=getchar())<='9'&&c>='0')x=x+(c&15)*l,l*=0.1;
        n=x*f;
        if(c==EOF)ans=0;
    }
    void write(){}
    void write1(string s){
        int n=s.size();
        for(int i=0;i<n;i++)putchar(s[i]);
    }
    void write1(const char *s){
        int n=strlen(s);
        for(int i=0;i<n;i++)putchar(s[i]);
    }
    void write1(char s){putchar(s);}
    void write1(float s,int x=6){
        char y[10001];
        sprintf(y,"%%.%df",x);
        printf(y,s);
    }
    void write1(double s,int x=6){
        char y[10001];
        sprintf(y,"%%.%dlf",x);
        printf(y,s);
    }
    void write1(long double s,int x=6){
        char y[10001];
        sprintf(y,"%%.%dLf",x);
        printf(y,s);
    }
    template<typename T>void write1(T n){
        if(n<0)n=-n,putchar('-');
        if (n>9)write1(n/10);
        putchar('0'+n%10);
    }
    template<typename T>friend ins operator>>(ins x,T &n);
    template<typename T>friend ins operator<<(ins x,T n);
    operator bool(){return ans;}
};
template<typename T>ins operator>>(ins x,T &n){
    if(!x.ans)return x;
    x.read1(n);return x;
}
template<typename T>ins operator<<(ins x,T n){
    x.write1(n);
    return x;
}
ins yin;
ins yout;
#endif
int ans,h[300010];
signed main(){
	int n,k;yin>>n>>k;
	for(int i=1;i<=n;i++){
		int x;yin>>x;
		if(x<=n)h[x]++;
	}
	int s=k;
	for(int i=0;i<=n+1;i++){
		if(h[i]<s)ans+=(s-h[i])*i,s=h[i];
		// cout<<ans<<endl;
	}yout<<ans;
	return 0;
}