#include <bits/stdc++.h>
struct edge {
  int to, nxt, cap, cost;
} e[219744];
int head[180], cnt = 1, n, k, a[88], pre[88], c[88], T, tot[88];
inline void addedge(int u, int v, int flow, int cost) {
  e[++cnt] = (edge){v, head[u], flow, cost};
  head[u] = cnt;
  e[++cnt] = (edge){u, head[v], 0, -cost};
  head[v] = cnt;
}
std::queue<int> q;
bool spfa(int& flow, int& cost) {
  static int a[180], d[180], pre_e[180], vis[180];
  memset(a, 0x3f, sizeof a);
  memset(d, 0x3f, sizeof a);
  memset(vis, 0, sizeof a);
  memset(pre_e, 0, sizeof a);
  *d = 0;
  for (q.push(0); !q.empty();) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = head[u]; i; i = e[i].nxt)
      if (e[i].cap && d[e[i].to] > d[u] + e[i].cost) {
        d[e[i].to] = d[u] + e[i].cost;
        a[e[i].to] = std::min(a[u], e[i].cap);
        pre_e[e[i].to] = i;
        if (!vis[e[i].to]) vis[e[i].to] = 1, q.push(e[i].to);
      }
  }
  if (d[T] == 0x3f3f3f3f) return 0;
  flow += a[T];
  cost += d[T] * a[T];
  for (int i = T; i; i = e[pre_e[i] ^ 1].to) {
    e[pre_e[i]].cap -= a[T];
    e[pre_e[i] ^ 1].cap += a[T];
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &k);
  T = n * 2 + 1;
  for (int i = 1; i <= n; ++i) {
    addedge(i, i + n, 1, 0);
    addedge(i + n, T, 1, 0);
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
  for (int i = 1; i <= n; ++i) {
    addedge(0, i, 1, c[a[i]]);
    if (pre[a[i]]) addedge(i - 1, pre[a[i]] + n, 1, -c[a[i]]);
    pre[a[i]] = i;
  }
  for (int i = 1; i < n; ++i) addedge(i, i + 1, k - 1, 0);
  int flow = 0, cost = 0;
  while (spfa(flow, cost))
    ;
  printf("%d\n", cost);
  return 0;
}
