#include<bits/stdc++.h>

using namespace std;

#define rg register
#define In inline
#define ll long long
#define rep(i,l,r) for(rg int i = (l);i <= (r);i++)
#define dwn(i,r,l) for(rg int i = (r);i >= (l);i--)
#define mp make_pair
#define fi first
#define se second

const int N = 2e5;

namespace IO{
	In ll read(){
		ll s = 0,ww = 1;
		char ch = getchar();
		while(ch < '0' || ch > '9'){if(ch == '-')ww = -1;ch = getchar();}
		while('0' <= ch && ch <= '9'){s = 10 * s + ch - '0';ch = getchar();}
		return s * ww;
	}
	In void write(ll x){
		if(x < 0)putchar('-'),x = -x;
		if(x > 9)write(x / 10);
		putchar('0' + x % 10);
	}
};
using namespace IO;

ll n,v[2*N+5];
priority_queue<ll,vector<ll>,greater<ll> > pq;

void solve(){
	rep(i,1,n){
		pq.push(v[n+i]);
		pq.push(v[n-i+1]);
		pq.pop();
	}
	ll ans = 0;
	while(!pq.empty()){
		ans += pq.top();
		pq.pop();
	}
	write(ans),putchar('\n');
}

int main(){
//	freopen("B.in","r",stdin);
//	freopen("B.out","w",stdout);
// USE LONG LONG
	n = read();
	rep(i,1,2 * n)v[i] = read();
	solve();
	return 0;
}
// T: Think
// E: Enough array size
// M: Memory limit
// P: Precision
// B: Boundary
// O: Overflow
// T: Time limit
// M: Mod
// F: File


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,x,n) for(i=x;i<=n;i++)
#define foreach(c,itr) for(__typeof(c)::iterator itr=c.begin();itr!=c.end();itr++)
#define all(v) v.begin(),v.end()
#define p_b push_back
#define fr first
#define sc second
#define m_p make_pair
#define zero(a) memset(a,0,sizeof(a))
#define set_P setprecision
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f;
ll gcd(ll x,ll y) {return x%y==0 ? y:gcd(y,x%y);}
int i,j;

int n,k;
int a[300005];
int num[300005];

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin>>n>>k;
	Rep(i,1,n){
		cin>>a[i];
		num[a[i]]++;
	}
	ll ans=0;
	for(i=1;i<=k;i++){
		int pos=0;
		while(num[pos]>0){
			num[pos]--;
			pos++;
		}
		ans+=pos;
	}
	cout<<ans<<endl;
	return 0;
}
