#include <bits/stdc++.h>
using namespace std;
int32_t seed;
mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());
inline int32_t rnd(int32_t l = 0, int32_t r = INT_MAX) {
  return uniform_int_distribution<int32_t>(l, r)(rng);
}
template <typename T, typename G>
ostream &operator<<(ostream &out, const pair<T, G> &a) {
  return out << "(" << a.first << " , " << a.second << ")";
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &a) {
  out << "[";
  for (const auto &i : a) out << i << " , ";
  return out << "]" << endl;
}
template <typename T>
ostream &operator<<(ostream &out, const set<T> &a) {
  out << "{";
  for (const auto &i : a) out << i << " , ";
  return out << "}" << endl;
}
template <typename T, typename G>
ostream &operator<<(ostream &out, const map<T, G> &a) {
  out << "<";
  for (const auto &i : a) out << i << " , ";
  return out << ">" << endl;
}
template <typename T, size_t N>
typename enable_if<!is_same<typename remove_cv<T>::type, char>::value,
                   ostream &>::type
operator<<(ostream &out, T (&a)[N]) {
  out << '[';
  for (size_t i = 0; i < N; ++i) out << a[i] << " , ";
  out << "]" << endl;
  return out;
}
template <typename T, typename G>
class mcmf {
 public:
  static constexpr T eps = (T)1e-9;
  struct edge {
    int32_t from;
    int32_t to;
    T c;
    T f;
    G cost;
  };
  vector<vector<int32_t> > g;
  vector<edge> edges;
  vector<G> d;
  vector<int32_t> q;
  vector<bool> in_queue;
  vector<int32_t> pe;
  int32_t n;
  int32_t st, fin;
  T flow;
  G cost;
  mcmf(int32_t _n, int32_t _st, int32_t _fin) {
    n = _n + 1;
    st = _st;
    fin = _fin;
    assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin);
    g.resize(n);
    d.resize(n);
    in_queue.resize(n);
    pe.resize(n);
    flow = 0;
    cost = 0;
  }
  void clear_flow() {
    for (const edge &e : edges) e.f = 0;
    flow = 0;
  }
  void add(int32_t from, int32_t to, T forward_cap, T backward_cap, G cost) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    g[from].push_back((int32_t)edges.size());
    edges.push_back({from, to, forward_cap, 0, cost});
    g[to].push_back((int32_t)edges.size());
    edges.push_back({to, from, backward_cap, 0, -cost});
  }
  bool expath() {
    fill(d.begin(), d.end(), numeric_limits<G>::max());
    q.clear();
    q.push_back(st);
    d[st] = 0;
    in_queue[st] = true;
    int32_t beg = 0;
    bool found = false;
    while (beg < (int32_t)q.size()) {
      int32_t i = q[beg++];
      if (i == fin) {
        found = true;
      }
      in_queue[i] = false;
      for (int32_t id : g[i]) {
        const edge &e = edges[id];
        if (e.c - e.f > eps && d[i] + e.cost < d[e.to]) {
          d[e.to] = d[i] + e.cost;
          pe[e.to] = id;
          if (!in_queue[e.to]) {
            q.push_back(e.to);
            in_queue[e.to] = true;
          }
        }
      }
    }
    if (found) {
      T push = numeric_limits<T>::max();
      int32_t v = fin;
      while (v != st) {
        const edge &e = edges[pe[v]];
        push = min(push, e.c - e.f);
        v = e.from;
      }
      v = fin;
      while (v != st) {
        edge &e = edges[pe[v]];
        e.f += push;
        edge &back = edges[pe[v] ^ 1];
        back.f -= push;
        v = e.from;
      }
      flow += push;
      cost += push * d[fin];
    }
    return found;
  }
  pair<T, G> max_flow_min_cost() {
    while (expath()) {
    }
    return {flow, cost};
  }
};
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int32_t n, k, i, a;
  cin >> n >> k;
  mcmf<int32_t, int64_t> mf(n + 3, 0, n + 2);
  mf.add(0, n + 1, k, 0, 0);
  for (i = 1; i <= n; i++) {
    cin >> a;
    mf.add(n + 1, i, 1, 0, a);
    if (i > 1) mf.add(i - 1, i, k, 0, 0);
  }
  for (i = 1; i <= n; i++) {
    cin >> a;
    mf.add(i, n + 2, 1, 0, a);
  }
  cout << mf.max_flow_min_cost().second;
  return 0;
}
