#include <bits/stdc++.h>
const int inf = 0x3F3F3F3F;
struct edg {
  int v, c, w;
  edg *e, *f;
} ES[(80 * (80 - 1) / 2 + 80 * 3 + (80 * 2 + 4) + 1) * 2],
    *ER = ES, *EA[(80 * 2 + 4)], *EC[(80 * 2 + 4)];
inline void edg_ins(int u, int v, int c, int w) {
  *ER = (edg){v, c, +w, EA[u], ER + 1}, EA[u] = ER++;
  *ER = (edg){u, 0, -w, EA[v], ER - 1}, EA[v] = ER++;
}
int dis[(80 * 2 + 4)], dep[(80 * 2 + 4)], V, Ql, Qr,
    Q[(80 * 2 + 4) * (80 * (80 - 1) / 2 + 80 * 3 + (80 * 2 + 4) + 1)];
bool inQ[(80 * 2 + 4)];
inline void upd(int u, int s, int d) {
  if (dis[u] != s ? dis[u] > s : dep[u] > d) {
    dis[u] = s, dep[u] = d;
    if (!inQ[u]) Q[++Qr] = u;
  }
}
inline bool spa(int s, int t) {
  int u;
  edg *e;
  memset(dis, 0x3F, V * sizeof(int));
  memset(dep, 0xFF, V * sizeof(int));
  Ql = Qr = -1, Q[++Qr] = t, dis[t] = dep[t] = 0;
  while (Ql < Qr)
    for (e = EA[u = Q[++Ql]], inQ[u] = false; e; e = e->e)
      if (e->f->c) upd(e->v, dis[u] - e->w, dep[u] + 1);
  return dis[s] < inf;
}
inline int dfs(int u, int t, int c = inf) {
  if (u == t || c == 0) return c;
  int f = 0, d;
  for (edg *e = EC[u]; e && c; e = e->e)
    if (EC[u] = e, dis[u] == dis[e->v] + e->w && dep[u] == dep[e->v] + 1 &&
                       (d = dfs(e->v, t, std::min(c, e->c))))
      e->c -= d, e->f->c += d, c -= d, f += d;
  return f;
}
inline int dnc(int s, int t) {
  int w = 0;
  while (spa(s, t)) memcpy(EC, EA, V * sizeof(edg *)), w += dis[s] * dfs(s, t);
  return w;
}
int n, m, p, q, s, t, i, j, a[80 + 1], w[80 + 1];
int main() {
  scanf("%d %d", &n, &m);
  p = 0, q = n * 2 + 1, s = q + 1, t = s + 1, V = t + 1;
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (i = 1; i <= n; ++i) scanf("%d", &w[i]);
  edg_ins(q, p, m, 0);
  for (i = 1; i <= n; ++i)
    edg_ins(p, i, 1, w[a[i]]), edg_ins(n + i, q, 1, 0), edg_ins(s, n + i, 1, 0),
        edg_ins(i, t, 1, 0);
  for (i = 1; i < n; ++i)
    for (j = i + 1; j <= n; ++j)
      edg_ins(n + i, j, 1, a[i] != a[j] ? w[a[j]] : 0);
  printf("%d\n", dnc(s, t));
  return 0;
}
