#include <bits/stdc++.h>
using namespace std;
const int N = 2300;
const long long inf = 1ll << 50;
int n, m, d[N];
long long a[N], b[N], ans;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%I64d", &b[i]);
  a[0] = b[0] = inf;
  for (int ti = 1; ti <= m; ti++) {
    long long mn = inf;
    int qa, qb, q;
    int ma = 0;
    for (int k = 1; k <= n; k++) {
      if (a[ma] > a[k]) ma = k;
      if (a[ma] + b[k] < mn) {
        qa = ma, qb = k;
        mn = a[ma] + b[k];
      }
    }
    for (int i = 1, j = 1; i < n; i = j, j = i) {
      while (j < n && (d[j] < 0) == (d[i] < 0)) j++;
      ma = 0;
      if (d[i] < 0) {
        for (int k = j; k >= i; k--) {
          if (a[ma] > a[k]) ma = k;
          if (a[ma] + b[k] < mn) {
            qa = ma, qb = k;
            mn = a[ma] + b[k];
          }
        }
      }
    }
    ans += a[qa] + b[qb];
    a[qa] = b[qb] = inf;
    if (qa <= qb)
      q = -1;
    else
      q = 1, swap(qa, qb);
    for (int i = qa; i <= qb - 1; i++) d[i] += q;
  }
  cout << ans << endl;
  return 0;
}
