#include <bits/stdc++.h>
using namespace std;
const int N = 4405;
const int inf = 0x3f3f3f3f;
int n, k, a[N], b[N];
class Flows {
 private:
  struct edge {
    int from, to, cap, flow, cost;
    edge(int from = 0, int to = 0, int cap = 0, int flow = 0, int cost = 0) {
      this->from = from;
      this->to = to;
      this->cap = cap;
      this->flow = flow;
      this->cost = cost;
    }
    int other(edge ed, int u) { return (ed.from == u ? ed.to : ed.from); }
  } E;
  int S, T, par[N];
  long long dist[N];
  vector<int> g[N];
  vector<edge> e;
  bool inqueue[N];
  queue<int> q;
  bool SPFA() {
    memset(par, -1, sizeof(par));
    memset(dist, 0x3f, sizeof(dist));
    memset(inqueue, 0, sizeof(inqueue));
    inqueue[S] = true;
    par[S] = inf;
    dist[S] = 0;
    q.push(S);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      inqueue[u] = false;
      for (int i = 0; i < g[u].size(); i++) {
        int V = g[u][i];
        edge ed = e[V];
        int v = E.other(ed, u);
        if (dist[v] > dist[u] + ed.cost && ed.flow < ed.cap) {
          dist[v] = dist[u] + ed.cost;
          par[v] = V;
          if (!inqueue[v]) {
            inqueue[v] = true;
            q.push(v);
          }
        }
      }
    }
    return par[T] != -1;
  }
  int edmond_karp() {
    int u = T;
    long long delta = inf;
    while (u != S) {
      delta = min(delta, (long long)e[par[u]].cap - (long long)e[par[u]].flow);
      u = E.other(e[par[u]], u);
    }
    u = T;
    while (u != S) {
      e[par[u]].flow += delta;
      e[par[u] ^ 1].flow -= delta;
      u = E.other(e[par[u]], u);
    }
    return delta;
  }

 public:
  void init(int _S, int _T) {
    S = _S;
    T = _T;
  }
  void addEdge(int u, int v, int cap, int flow, int cost) {
    g[u].push_back(e.size());
    e.push_back(edge(u, v, cap, flow, cost));
    g[v].push_back(e.size());
    e.push_back(edge(v, u, 0, 0, -cost));
  }
  pair<long long, int> solve() {
    int maxflow = 0;
    long long mincost = 0;
    while (SPFA()) maxflow += edmond_karp();
    for (int i = 0; i < e.size(); i++)
      if (e[i].flow > 0) mincost += 1LL * e[i].flow * e[i].cost;
    return make_pair(mincost, maxflow);
  }
} mcmf;
void input() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
}
void solve() {
  mcmf.init(0, n + 2);
  mcmf.addEdge(n + 1, n + 2, k, 0, 0);
  for (int i = 1; i <= n; i++) mcmf.addEdge(0, i, 1, 0, a[i]);
  for (int i = 1; i <= n; i++) mcmf.addEdge(i, n + 1, 1, 0, b[i]);
  for (int i = 1; i < n; i++) mcmf.addEdge(i, i + 1, inf, 0, 0);
  pair<long long, int> res = mcmf.solve();
  cout << res.first;
}
signed main() {
  input();
  solve();
  return 0;
}
