#include <bits/stdc++.h>
using namespace std;
int MOD = 1e9 + 7;
long long INF = 1e14;
struct edge {
  int from, to;
  long long cap, weight;
  edge *rev;
  edge(int u, int v, int c, int w)
      : from(u), to(v), cap(c), weight(w), rev(NULL) {}
};
int n, s, t;
edge *p[2205];
long long dist[2205];
int vis[2205];
vector<edge *> g[2205];
void addedge(int u, int v, int c, int w) {
  edge *in = new edge(u, v, c, w);
  edge *out = new edge(v, u, 0, -w);
  in->rev = out;
  out->rev = in;
  g[u].push_back(in);
  g[v].push_back(out);
}
long long mincostflow() {
  long long mxf = 0, mnc = 0;
  for (;;) {
    for (int i = 0; i < n; i++) p[i] = NULL, vis[i] = 0;
    for (int i = 0; i < n; i++) dist[i] = INF;
    queue<int> q;
    q.push(s);
    dist[s] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      vis[u] = 0;
      for (edge *e : g[u]) {
        int v = e->to;
        if (e->cap > 0 && dist[u] + e->weight < dist[v]) {
          dist[v] = dist[u] + e->weight;
          p[v] = e;
          if (!vis[v]) q.push(v), vis[v] = 1;
        }
      }
    }
    if (dist[t] == INF) break;
    long long fo = INF;
    for (int u = t; p[u] != NULL; u = p[u]->from) fo = min(fo, p[u]->cap);
    for (int u = t; p[u] != NULL; u = p[u]->from) {
      p[u]->cap -= fo, p[u]->rev->cap += fo;
      mnc += fo * p[u]->weight;
    }
    mxf += fo;
  }
  return mnc;
}
int N, k, a[2205], b[2205];
int solve() {
  cin >> N >> k;
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 0; i < N; i++) cin >> b[i];
  n = N + 3, s = N, t = N + 2;
  int sp = N + 1;
  addedge(s, sp, k, 0);
  for (int i = 0; i < N; i++) addedge(sp, i, 1, a[i]);
  for (int i = 0; i + 1 < N; i++) addedge(i, i + 1, INF, 0);
  for (int i = 0; i < N; i++) addedge(i, t, 1, b[i]);
  cout << mincostflow() << endl;
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  solve();
  return 0;
}
