#include <bits/stdc++.h>
using namespace std;
int inf_int = 1e9;
long long inf_ll = 1e17;
const double pi = 3.1415926535898;
const long long mod = 99990001;
const int MAXN = 5e3 + 10;
bool debug = false;
struct Edge {
  int a, b, c, flow, cost;
};
struct MIN_FLOW {
  vector<Edge> e;
  vector<int> g[MAXN];
  int n, s, t;
  int id[MAXN];
  long long dis[MAXN];
  int from[MAXN];
  void init(int N, int S, int T) {
    n = N;
    s = S;
    t = T;
  }
  void add_edge(int a, int b, int c, int cost) {
    Edge e1 = {a, b, c, 0, cost};
    Edge e2 = {b, a, 0, 0, -cost};
    g[a].push_back(e.size());
    e.push_back(e1);
    g[b].push_back(e.size());
    ;
    e.push_back(e2);
  }
  long long get_val(int k) {
    int flow = 0;
    long long cost = 0;
    while (1) {
      deque<int> q;
      fill(id, id + n, 0);
      fill(dis, dis + n, inf_ll);
      dis[s] = 0;
      id[s] = 1;
      q.push_front(s);
      while (!q.empty()) {
        int v = q.front();
        q.pop_front();
        id[v] = 2;
        for (int ind : g[v]) {
          Edge& edge = e[ind];
          int to = edge.b;
          if (edge.c > edge.flow && dis[edge.b] > dis[v] + edge.cost) {
            if (id[to] == 0) {
              q.push_back(to);
            } else if (id[to] == 2) {
              q.push_front(to);
            }
            id[to] = 1;
            dis[to] = dis[v] + edge.cost;
            from[to] = ind;
          }
        }
      }
      if (dis[t] == inf_ll) break;
      int addflow = min(inf_int, k - flow);
      int v = t;
      while (v != s) {
        int ind = from[v];
        addflow = min(addflow, e[ind].c - e[ind].flow);
        v = e[ind].a;
      }
      v = t;
      while (v != s) {
        int ind = from[v];
        cost += 1ll * e[ind].cost * addflow;
        e[ind].flow += addflow;
        e[ind ^ 1].flow -= addflow;
        v = e[ind].a;
      }
      flow += addflow;
      if (flow == k) break;
    }
    return cost;
  }
} flow;
int a[MAXN], b[MAXN];
void solve() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
  }
  int s = 0, t = n + 3;
  flow.init(n + 4, s, t);
  for (int i = 1; i <= n; ++i) {
    flow.add_edge(s, i, 1, a[i]);
    flow.add_edge(i, t, 1, b[i]);
  }
  for (int i = 2; i <= n; ++i) {
    flow.add_edge(i - 1, i, k, 0);
  }
  cout << flow.get_val(k);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
