#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) {
    if (vi != v.begin()) os << ", ";
    os << *vi;
  }
  os << "}";
  return os;
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}
long long T, N, M, K;
int v[2240], v2[2240];
int ned;
int first[100009], to[900009], nxt[900009], prv[100009];
long long cap[900009], cost[900009], dist[100009], pot[100009];
void init() {
  memset(first, -1, sizeof first);
  ned = 0;
}
void add(int u, int v, long long f, long long c) {
  to[ned] = v, cap[ned] = f;
  cost[ned] = c, nxt[ned] = first[u];
  first[u] = ned++;
  to[ned] = u, cap[ned] = 0;
  cost[ned] = -c, nxt[ned] = first[v];
  first[v] = ned++;
}
bool dijkstra(int s, int t, int n) {
  memset(&prv, -1, sizeof prv);
  for (int i = 1; i <= n; i++) dist[i] = 0x3f3f3f3f3f3f3f3f;
  set<pair<long long, int> > q;
  q.insert(make_pair(0LL, s));
  dist[s] = prv[s] = 0;
  while (!q.empty()) {
    int u = q.begin()->second;
    q.erase(q.begin());
    for (int e = first[u]; e != -1; e = nxt[e]) {
      if (cap[e] <= 0) continue;
      int v = to[e];
      long long new_dist = dist[u] + cost[e] + pot[u] - pot[v];
      if (new_dist < dist[v]) {
        q.erase(make_pair(dist[v], v));
        dist[v] = new_dist;
        prv[v] = e;
        q.insert(make_pair(new_dist, v));
      }
    }
  }
  return prv[t] != -1;
}
long long augment(int s, int t, long long &maxflow, int n) {
  long long flow = maxflow;
  for (int i = t; i != s; i = to[prv[i] ^ 1]) flow = min(flow, cap[prv[i]]);
  for (int i = t; i != s; i = to[prv[i] ^ 1]) {
    cap[prv[i]] -= flow;
    cap[prv[i] ^ 1] += flow;
  }
  maxflow -= flow;
  long long flowCost = flow * (dist[t] - pot[s] + pot[t]);
  for (int i = 1; i <= n; i++)
    if (prv[i] != -1) pot[i] += dist[i];
  return flowCost;
}
long long mincostmaxflow(int s, int t, long long &maxflow, int n) {
  long long flowCost = 0;
  memset(pot, 0, sizeof pot);
  while (maxflow > 0 && dijkstra(s, t, n)) {
    flowCost += augment(s, t, maxflow, n);
  }
  return flowCost;
}
void solve() {
  init();
  for (int i = (int)(0); (i) < int(N); (i)++) add(0, i + 1, 1, v[i]);
  for (int i = (int)(0); (i) < int(N); (i)++) add(i + 1, N + 1, 1, v2[i]);
  for (int i = (int)(0); (i) < int(N - 1); (i)++)
    add(i + 1, i + 2, 0x3f3f3f3f, 0);
  cout << mincostmaxflow(0, N + 1, M, N + 2) << "\n";
}
int main() {
  cin >> N >> M;
  for (int i = (int)(0); (i) < int(N); (i)++) cin >> v[i];
  for (int i = (int)(0); (i) < int(N); (i)++) cin >> v2[i];
  solve();
  return 0;
}
