#include <bits/stdc++.h>
using namespace std;
const int N = 7e3 + 5;
const long long mod = 1e9 + 7;
const long long inf = 1e12;
struct min_cost {
  struct edge {
    int from, to;
    long long cp, fl, cs;
  };
  vector<edge> edges;
  vector<int> adj[N];
  void addEdge(int i, int j, long long cp, long long cs) {
    edges.push_back({i, j, cp, 0, cs});
    adj[i].push_back(edges.size() - 1);
    edges.push_back({j, i, 0, 0, -cs});
    adj[j].push_back(edges.size() - 1);
  }
  long long seen[N], dist[N], pai[N], cost, flow;
  int turn;
  long long spfa(int s, int t) {
    turn++;
    queue<int> q;
    q.push(s);
    for (int i = 0; i < N; i++) dist[i] = inf;
    dist[s] = 0;
    seen[s] = turn;
    while (q.size()) {
      int u = q.front();
      q.pop();
      seen[u] = 0;
      for (auto e : adj[u]) {
        int v = edges[e].to;
        if (edges[e].cp > edges[e].fl && dist[u] + edges[e].cs < dist[v]) {
          dist[v] = dist[u] + edges[e].cs;
          pai[v] = e ^ 1;
          if (seen[v] < turn) {
            seen[v] = turn;
            q.push(v);
          }
        }
      }
    }
    if (dist[t] == inf) return 0;
    long long nfl = inf;
    for (int u = t; u != s; u = edges[pai[u]].to)
      nfl = min(nfl, edges[pai[u] ^ 1].cp - edges[pai[u] ^ 1].fl);
    cost += dist[t] * nfl;
    for (int u = t; u != s; u = edges[pai[u]].to) {
      edges[pai[u]].fl -= nfl;
      edges[pai[u] ^ 1].fl += nfl;
    }
    return nfl;
  }
  void mncost(int s, int t) {
    cost = flow = 0;
    while (long long fl = spfa(s, t)) flow += fl;
  }
};
long long a[N], b[N];
int main() {
  min_cost f;
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    f.addEdge(2 * n, i, 1, a[i]);
    if (i != 0) f.addEdge(i - 1, i, k, 0ll);
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &b[i]);
    f.addEdge(i, 2 * n + 1, 1, b[i]);
  }
  f.addEdge(2 * n + 2, 2 * n, k, 0ll);
  f.mncost(2 * n + 2, 2 * n + 1);
  printf("%lld\n", f.cost);
  return 0;
}
