#include <bits/stdc++.h>
using namespace std;
const long long sz = 3e3 + 88;
const long long inf = 1e18 + 88;
const long long s = 3e3, t = s + 1, rt = t + 1;
struct _edge {
  long long v, to, cap, flow, cost;
};
vector<_edge> edge;
vector<long long> g[sz];
long long d[sz], pi[sz], p[sz], a[sz], b[sz];
long long n, k;
void add(long long v, long long to, long long cap, long long cost) {
  g[v].push_back(edge.size());
  edge.push_back({v, to, cap, 0, cost});
  g[to].push_back(edge.size());
  edge.push_back({to, v, 0, 0, -cost});
}
void get(long long id, long long &v, long long &to, long long &cap,
         long long &f, long long &cost) {
  v = edge[id].v;
  to = edge[id].to, cap = edge[id].cap, f = edge[id].flow, cost = edge[id].cost;
}
bool dijkstra() {
  long long i;
  set<pair<long long, long long> > dist;
  for (i = 0; i < sz; i++) {
    p[i] = -1;
    d[i] = inf;
  }
  d[s] = 0;
  d[t] = inf;
  d[rt] = inf;
  dist.insert({0, s});
  while (!dist.empty()) {
    long long v = dist.begin()->second;
    dist.erase({d[v], v});
    for (i = 0; i < g[v].size(); i++) {
      long long id = g[v][i], to, cap, cost, f;
      get(id, v, to, cap, f, cost);
      cost += pi[v] - pi[to];
      if (cap > f && d[to] > d[v] + cost) {
        dist.erase({d[to], to});
        d[to] = d[v] + cost;
        p[to] = id;
        dist.insert({d[to], to});
      }
    }
  }
  for (i = 0; i < sz; i++)
    if (d[sz] != inf) pi[i] += d[i];
  return d[rt] != inf;
}
void flow() {
  long long v = rt, curflow = inf;
  while (v != s) {
    long long id = p[v];
    curflow = min(curflow, edge[id].cap - edge[id].flow);
    v = edge[id].v;
  }
  v = rt;
  while (v != s) {
    long long id = p[v];
    edge[id].flow += curflow;
    edge[id ^ 1].flow -= curflow;
    v = edge[id].v;
  }
}
long long mincostflow() {
  long long ans = 0;
  while (dijkstra()) flow();
  for (long long i = 0; i < edge.size(); i++)
    if (edge[i].cap > 0) ans += edge[i].flow * edge[i].cost;
  return ans;
}
int main() {
  long long i;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    add(s, i, 1, a[i]);
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
    add(i, t, 1, b[i]);
  }
  for (i = 1; i < n; i++) add(i - 1, i, k, 0);
  add(t, rt, k, 0);
  cout << mincostflow();
  return 0;
}
