#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
 
void print(vector <vector <ll>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}

ll solve(vector <ll> &A, ll a, ll x, ll n) {
	vector <vector<ll>> X(a,vector <ll>(n+1,0LL));
	for (ll i=0;i<n;i++) {
		for (ll k=n-1;k>=1;k--) {
			for (ll j=0;j<a;j++) {
				if (X[j][k]>0LL) {
				X[(j+A[i])%a][k+1]=max(X[j][k]+A[i],X[(j+A[i])%a][k+1]);
				}
				//cout<<a<<" "<<kiek<<" "<<Y[kiek%a][k+1]<<endl;
				}
			}
		X[A[i]%a][1]=max(X[A[i]%a][1],A[i]);
		//cout<<a<<" "<<i<<endl;
		//print(X);
		}
	ll did=X[x%a][a];
	//cout<<a<<" "<<did<<endl;
	if (did==0LL) {return x;}
	ll ats=(x-did)/a;
	//cout<<a<<" "<<did<<" "<<ats<<endl;
	return ats;
	}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    ll x;
    cin>>n>>x;
    vector <ll> A(n);
    for (ll i=0;i<n;i++) {cin>>A[i];}
    ll ats=x;
    for (ll i=1;i<=n;i++) {
		ll s=solve(A,i,x,n);
		ats=min(ats,s);
		}
	cout<<ats<<endl;
    return 0;
}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define N 500100
#define MOD 1000000007  //998244353
#define ll long long
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define rep3(i, a, b) for(int i = a; i >= b; --i)
#define eb emplace_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
struct Setup_io {
	Setup_io() {
		ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
		cout << fixed << setprecision(15);
	}
} setup_io;



int main() {
	int n;
	ll a[N];
	ll x;
	ll ans = 0;
	priority_queue<ll>pq;
	cin >> n;
	rep(i, (2*n))cin >> a[i];
	rep(i, n) {
		pq.push(-a[n + i]);
		pq.push(-a[n - 1 - i]);
		ans += a[n + i];
		ans += a[n - 1 - i];
		x = pq.top();
		ans += x;
		pq.pop();
	}
	cout << ans << endl;
	return 0;
}
