#include "bits/stdc++.h"

using namespace std;

void Main() {
    int N, K;
    cin >> N >> K;
    map<int, int> m;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        m[a] += 1;
    }

    vector<int> numOfA;
    for (int i = 0; i < N; ++i) {
        if (m.count(i) == 0) {
            break;
        }
        numOfA.push_back(m[i]);
    }
    for (int i = 1; i < numOfA.size(); ++i) {
        numOfA[i] = min(numOfA[i - 1], numOfA[i]);
    }
    if (numOfA.size() == 0) {
        cout << 0 << endl;
        return;
    }
    vector<int> combination;
    for (int i = 0; i < numOfA.back(); ++i) {
        combination.push_back(numOfA.size());
    }
    for (int i = numOfA.size() - 2; i >= 0; --i) {
        int n = numOfA[i] - numOfA[i + 1];
        for (int j = 0; j < n; ++j) {
            combination.push_back(i + 1);
        }
    }

    int ans = 0;
    for (int i = 0; i < K; ++i) {
        if (i == combination.size()) {
            break;
        }
        ans += combination[i];
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

// #include <atcoder/all>
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

int n;
ll a[200009], b[200009];

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

    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    ll sum = 0;
    rep(i, n) sum += a[i];

    vector<int> odd, even;
    rep(i, n)(i & 1 ? odd : even).push_back(b[i] - a[i]);

    sort(ALL(odd), greater<int>());
    sort(ALL(even), greater<int>());

    ll ans = sum;
    rep(i, n / 2) chmax(ans, sum += odd[i] + even[i]);

    cout << ans << endl;

    return 0;
}