#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e4 + 5, INFC = 0x3f3f3f3f;
const ll INFW = 0x3f3f3f3f3f3f3f3fLL;
struct Eg {
  int to, nxt, c, w;
} e[N * 20];
int n, k, S, T, a[N], b[N], pre[N], hd[N], cntE = 1;
int incf[N], inq[N];
ll ans, d[N];
queue<int> q;
void add(int u, int v, int c, int w) {
  e[++cntE] = (Eg){v, hd[u], c, w}, hd[u] = cntE;
  e[++cntE] = (Eg){u, hd[v], 0, -w}, hd[v] = cntE;
}
bool SPFA() {
  memset(d, INFW, sizeof(ll[T + 1]));
  incf[S] = INFC, q.push(S), d[S] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop(), inq[u] = 0;
    for (int i = hd[u], v; i; i = e[i].nxt)
      if (e[i].c && d[v = e[i].to] > d[u] + e[i].w) {
        d[v] = d[u] + e[i].w, pre[v] = i;
        incf[v] = min(incf[u], e[i].c);
        if (!inq[v]) inq[v] = 1, q.push(v);
      }
  }
  return d[T] != INFW;
}
void upd() {
  for (int x = T, i; x != S; x = e[i ^ 1].to)
    e[i = pre[x]].c -= incf[T], e[i ^ 1].c += incf[T];
  ans += d[T] * incf[T];
}
int main() {
  scanf("%d%d", &n, &k), S = 3 * n + 2, T = S + 1;
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i) scanf("%d", b + i);
  for (int i = 1; i <= n; ++i) {
    add(S, i, 1, a[i]), add(i, i + n, 1, 0), add(i + n, i + 2 * n, 1, 0),
        add(i + 2 * n, 3 * n + 1, 1, b[i]);
    if (i < n)
      add(i + n, i + n + 1, INFC, 0);
    else
      add(3 * n + 1, T, k, 0);
  }
  while (SPFA()) upd();
  printf("%lld", ans);
  return 0;
}
