#include <bits/stdc++.h>
using namespace std;
struct CostFlow {
  static const int MXN = 205;
  static const long long INF = 102938475610293847LL;
  struct Edge {
    int v, r;
    long long f, c;
  };
  int n, s, t, prv[MXN], prvL[MXN], inq[MXN];
  long long dis[MXN], fl, cost;
  vector<Edge> E[MXN];
  void init(int _n, int _s, int _t) {
    n = _n;
    s = _s;
    t = _t;
    for (int i = 0; i < n; i++) E[i].clear();
    fl = cost = 0;
  }
  void add_edge(int u, int v, long long f, long long c) {
    E[u].push_back({v, int((E[v]).size()), f, c});
    E[v].push_back({u, int((E[u]).size()) - 1, 0, -c});
  }
  pair<long long, long long> flow(long long maxf = INF) {
    while (maxf) {
      for (int i = 0; i < n; i++) {
        dis[i] = INF;
        inq[i] = 0;
      }
      dis[s] = 0;
      queue<int> que;
      que.push(s);
      while (!que.empty()) {
        int u = que.front();
        que.pop();
        inq[u] = 0;
        for (int i = 0; i < int((E[u]).size()); i++) {
          int v = E[u][i].v;
          long long w = E[u][i].c;
          if (E[u][i].f > 0 && dis[v] > dis[u] + w) {
            prv[v] = u;
            prvL[v] = i;
            dis[v] = dis[u] + w;
            if (!inq[v]) {
              inq[v] = 1;
              que.push(v);
            }
          }
        }
      }
      if (dis[t] == INF) break;
      if (dis[t] >= 0) break;
      long long tf = maxf;
      for (int v = t, u, l; v != s; v = u) {
        u = prv[v];
        l = prvL[v];
        tf = min(tf, E[u][l].f);
      }
      for (int v = t, u, l; v != s; v = u) {
        u = prv[v];
        l = prvL[v];
        E[u][l].f -= tf;
        E[v][E[u][l].r].f += tf;
      }
      cost += tf * dis[t];
      fl += tf;
      maxf -= tf;
    }
    return {fl, cost};
  }
} f;
const int INF = 1e9 + 7, N = 82, M = 1e9;
int a[N], c[N];
signed main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  int s = 1, t = 2 * n + 2;
  f.init(n * 2 + 3, s, t);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1; i <= n; i++) {
    f.add_edge(i * 2, i * 2 + 1, 1, -M);
    f.add_edge(s, i * 2, 1, c[a[i]]);
    f.add_edge(i * 2 + 1, t, 1, 0);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int cost = (a[i] == a[j] ? 0 : c[a[j]]);
      f.add_edge(i * 2 + 1, j * 2, 1, cost);
    }
  }
  cout << f.flow(k).second + (long long)M * n << '\n';
}
