#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  for (x = c - '0'; (c = getchar()) >= '0' && c <= '9';)
    x = (x << 3) + (x << 1) + c - '0';
  return x;
}
struct edge {
  int nx, t, w, c;
} e[160 * 2 + 5];
int a[80 + 5], c[80 + 5], ls[80 + 5];
int h[80 + 5], en = 1, q[1000005], qn, inq[80 + 5], d[80 + 5], r[80 + 5];
inline void ins(int x, int y, int w, int c) {
  e[++en] = (edge){h[x], y, w, c};
  h[x] = en;
  e[++en] = (edge){h[y], x, 0, -c};
  h[y] = en;
}
bool spfa() {
  int i, j;
  memset(d, 40, sizeof(d));
  for (d[q[i = qn = 0] = 80 + 1] = 0; i <= qn; inq[q[i++]] = 0)
    for (j = h[q[i]]; j; j = e[j].nx)
      if (e[j].w && d[q[i]] + e[j].c < d[e[j].t]) {
        d[e[j].t] = d[q[i]] + e[j].c;
        r[e[j].t] = j;
        if (!inq[e[j].t]) inq[q[++qn] = e[j].t] = 1;
      }
  return d[80 + 2] < d[0];
}
int main() {
  int n, k, i, j, ans = 0, mn;
  n = read();
  k = read() - 1;
  for (i = 1; i <= n; ++i) a[i] = read();
  for (i = 1; i <= n; ++i) c[i] = read();
  ins(80 + 1, 1, k, 0);
  ins(n, 80 + 2, k, 0);
  for (i = 1; i < n; ++i) ins(i, i + 1, k, 0);
  for (i = 1; i <= n; ++i) {
    ans += c[a[i]];
    if (ls[a[i]])
      if (ls[a[i]] == i - 1)
        ans -= c[a[i]];
      else
        ins(ls[a[i]] + 1, i, 1, -c[a[i]]);
    ls[a[i]] = i;
  }
  while (spfa()) {
    for (mn = 1e9, i = 80 + 2; i != 80 + 1; i = e[r[i] ^ 1].t)
      mn = min(mn, e[r[i]].w);
    for (i = 80 + 2; i != 80 + 1; i = e[r[i] ^ 1].t)
      e[r[i]].w -= mn, e[r[i] ^ 1].w += mn;
    ans += d[80 + 2] * mn;
  }
  printf("%d", ans);
}
