#include <bits/stdc++.h>
#define endl '\n'

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

int n;
int a[MAXN];
int64_t sum = 0;

void read() {
	cin >> n;
	for(int i = 0; i < 2 * n; i++) {
		cin >> a[i];
		sum += a[i];
	}
}

void solve() {
	int r = 2 * n - 1;
	int64_t ans = 0;
	priority_queue<int> q;
	for(int i = n; i < 2 * n; i++) {
		ans += a[i];
	}

	for(int i = 0; i < n; i++) {
		q.push(a[r--]);
		if(q.top() > a[i]) {
			ans -= q.top();
			ans += a[i];
			q.pop();
			q.push(a[i]);
		}
	}

	cout << sum - ans << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	read();
	solve();
	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
template <typename _Tp>void read(_Tp &x){
	char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
	if(f)x=-x;
}
template <typename _Tp,typename... Args>void read(_Tp &t,Args &...args){read(t);read(args...);}
const int N=21;
std::vector<int> e[N];
int n,col[N];
long long ans;
void dfs(int dep,long long coef){
	if(dep==n){ans+=coef;
	return;}
	if(e[dep].empty())dfs(dep+1,coef*3LL);
	else{
		for(int i=0;i<3;++i){
			bool flag=true;
			for(auto v:e[dep]){
				if(col[v]==i){flag=false;break;}
			}
			if(flag)col[dep]=i,dfs(dep+1,coef),col[dep]=-1;
		}
	}
}
int main(){
	memset(col,-1,sizeof(col));
	int m;read(n,m);
	for(int i=1,x,y;i<=m;++i)read(x,y),--x,--y,e[x].pb(y),e[y].pb(x);
	dfs(0,1);
	printf("%lld\n",ans);
	return 0;
}