#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int t, w, f, fl, c, nx;
} e[40000 << 1];
int d[200], Ans, i, j, a[200], h[200], Num = 1, k, n, m, p[200], pre[200],
                                       L[200], c[200], s, t, Cnt, x, q[40000],
                                       l, r;
bool b[200];
inline int Min(int x, int y) { return x < y ? x : y; }
inline void Add(int x, int y, int w, int c) {
  e[++Num].t = y;
  e[Num].w = w;
  e[Num].c = c;
  e[Num].f = x;
  e[Num].nx = h[x];
  h[x] = Num;
  e[++Num].t = x;
  e[Num].w = -w;
  e[Num].f = y;
  e[Num].nx = h[y];
  h[y] = Num;
}
inline int Spfa() {
  memset(d, 63, sizeof(d));
  memset(b, 0, sizeof(b));
  memset(p, 0, sizeof(p));
  d[s] = l = 0;
  b[s] = 1;
  q[r = 1] = s;
  while (++l <= r) {
    x = q[l];
    b[x] = 0;
    for (i = h[x]; i; i = e[i].nx)
      if (e[i].c > e[i].fl && d[e[i].t] > d[x] + e[i].w) {
        d[e[i].t] = d[x] + e[i].w;
        p[e[i].t] = i;
        if (!b[e[i].t]) q[++r] = e[i].t, b[e[i].t] = 1;
      }
  }
  if (d[t] == d[0]) return d[0];
  for (i = p[t]; i; i = p[e[i].f]) e[i].fl++, e[i ^ 1].fl--;
  return d[t];
}
int main() {
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (i = 1; i <= n; i++) {
    pre[i] = L[a[i]];
    L[a[i]] = i;
    if (i == 1 || pre[i] != i - 1) Ans += c[a[i]];
  }
  for (i = 1; i <= n; i++) Add(i, i + 1, 0, k - 1);
  Cnt = n + 1;
  s = ++Cnt;
  for (i = 1; i <= n; i++)
    if (pre[i] && pre[i] != i - 1) {
      Add(s, pre[i] + 1, 0, 1);
      Add(pre[i] + 1, ++Cnt, 0, 1);
      Add(i, Cnt, -c[a[i]], 1);
    }
  t = ++Cnt;
  for (i = s + 1; i < t; i++) Add(i, t, 0, 1);
  while (1) {
    x = Spfa();
    if (x == d[0]) break;
    Ans += x;
  }
  printf("%d\n", Ans);
  return 0;
}
