#include <bits/stdc++.h>
using namespace std;
const int maxN = 100 * 2;
const int maxM = maxN * maxN;
const int inf = 1e8;
class Edge {
 public:
  int v, flow;
  long long w;
};
int n, K, m, S, T, Seq[maxN], Cst[maxN];
int ecnt = -1, Hd[maxN], Nt[maxM];
Edge E[maxM];
int Qu[maxN], inq[maxN], Flow[maxN], Path[maxN];
long long Dst[maxN];
void Add_Edge(int u, int v, int flow, long long w);
bool Spfa();
int main() {
  scanf("%d%d", &n, &K);
  memset(Hd, -1, sizeof(Hd));
  for (int i = 1; i <= n; i++) scanf("%d", &Seq[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &Cst[i]);
  int nS = n + n + 2;
  S = n + n + 1;
  T = n + n + 3;
  Add_Edge(S, nS, K, 0);
  for (int i = 1; i <= n; i++)
    Add_Edge(nS, i, 1, Cst[Seq[i]]), Add_Edge(i, i + n, 1, -inf),
        Add_Edge(i + n, T, 1, 0);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      Add_Edge(i + n, j, 1, Seq[i] == Seq[j] ? 0 : Cst[Seq[j]]);
  long long Ans = 1ll * n * inf;
  while (Spfa()) {
    if (Dst[T] > 0) break;
    Ans = Ans + Dst[T] * Flow[T];
    int now = T;
    while (now != S) {
      E[Path[now]].flow -= Flow[T];
      E[Path[now] ^ 1].flow += Flow[T];
      now = E[Path[now] ^ 1].v;
    }
  }
  printf("%I64d\n", Ans);
  return 0;
}
void Add_Edge(int u, int v, int flow, long long w) {
  Nt[++ecnt] = Hd[u];
  Hd[u] = ecnt;
  E[ecnt] = ((Edge){v, flow, w});
  Nt[++ecnt] = Hd[v];
  Hd[v] = ecnt;
  E[ecnt] = ((Edge){u, 0, -w});
  return;
}
bool Spfa() {
  memset(Dst, 63, sizeof(Dst));
  int ql = 0, qr = 1;
  Qu[1] = S;
  Dst[S] = 0;
  Flow[S] = inf;
  while (ql != qr) {
    ++ql;
    ql %= maxN;
    int u = Qu[ql];
    for (int i = Hd[u]; i != -1; i = Nt[i])
      if (E[i].flow && Dst[E[i].v] > Dst[u] + E[i].w) {
        Dst[E[i].v] = Dst[u] + E[i].w;
        Path[E[i].v] = i;
        Flow[E[i].v] = min(Flow[u], E[i].flow);
        if (!inq[E[i].v]) {
          ++qr;
          qr %= maxN;
          Qu[qr] = E[i].v;
          inq[E[i].v] = 1;
        }
      }
    inq[u] = 0;
  }
  return Dst[T] != Dst[0];
}
