#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200005;

int n;
int a[MAXN << 1];

priority_queue<int,vector<int>,greater<int> > taken;

int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= n * 2;i++)
		scanf("%d",&a[i]);
	for (int i = n;i >= 1;i--)
	{
		int u = a[i],v = a[2 * n - i + 1];
		if (u < v)
			swap(u,v);
		taken.push(u);
		if (taken.top() < v)
		{
			taken.pop();
			taken.push(v);
		}
	}
	long long ans = 0;
	while (!taken.empty())
	{
		ans += taken.top();
		taken.pop();
	}
	printf("%lld\n",ans);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
#define Bit(x, k) (((x) >> (k)) & 1)
#define Xor(x, k) ((x) ^ (1 << (k)))

signed main() {
  // freopen("in" , "r", stdin );
  cin.tie(0)->sync_with_stdio(0);
  int n; cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  int ans = 2e9;
  for (int mask = 0; mask < (1 << n); mask++) {
    int cal = 0, val = 0, mode = -1;
    for (int i = 0; i < n; i++) {
      int m = Bit(mask, i);
      if (m != mode) {
        mode = m;
        cal ^= val;
        val = a[i];
      }
      else val |= a[i];
    }
    cal ^= val;
    ans = min(ans, cal);
  }
  cout << ans << endl;
}
