#include <bits/stdc++.h>
using namespace std;
const int MAXN = 210;
const int MAXM = 200010;
queue<int> q;
int s, t, now, n;
struct Edge {
  int from, next, to, rest, cost;
} e[MAXM];
int head[MAXN], num = 1, dis[MAXN], vis[MAXN], Flow[MAXN], pre[MAXN];
inline void Add(int from, int to, int flow, int cost) {
  e[++num] = (Edge){from, head[from], to, flow, cost};
  head[from] = num;
  e[++num] = (Edge){to, head[to], from, 0, -cost};
  head[to] = num;
}
int RoadsExist() {
  q.push(s);
  memset(dis, 127, sizeof dis);
  dis[s] = 0;
  Flow[s] = 2147483647;
  pre[t] = 0;
  while (!q.empty()) {
    now = q.front();
    q.pop();
    vis[now] = 0;
    for (int i = head[now]; i; i = e[i].next)
      if (e[i].rest && dis[e[i].to] > dis[now] + e[i].cost) {
        dis[e[i].to] = dis[now] + e[i].cost;
        pre[e[i].to] = i;
        Flow[e[i].to] = min(Flow[now], e[i].rest);
        if (!vis[e[i].to]) {
          vis[e[i].to] = 1;
          q.push(e[i].to);
        }
      }
  }
  return pre[t];
}
int k, maxflow, mincost, sum;
int a[MAXN], c[MAXN], last[MAXN];
int main() {
  scanf("%d%d", &n, &k);
  s = 199;
  t = 200;
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
  for (int i = 1; i <= n; ++i) {
    Add(s, i, 1, c[a[i]]);
    if (i != 1) Add(i - 1, i, k - 1, 0);
    Add(i, i + n, 1, 0);
    if (last[a[i]]) Add(i - 1, last[a[i]] + n, 1, -c[a[i]]);
    Add(i + n, t, 1, 0);
    last[a[i]] = i;
  }
  while (RoadsExist()) {
    mincost += Flow[t] * dis[t];
    for (int i = t; i != s; i = e[pre[i]].from) {
      e[pre[i]].rest -= Flow[t];
      e[pre[i] ^ 1].rest += Flow[t];
    }
  }
  printf("%d\n", mincost);
}
