#include <bits/stdc++.h>
using namespace std;
const int maxN = 205, maxE = 1e3 + 7, S = 0;
int N, K, a[maxN], c[maxN], pos[maxN], head[maxN], cnt, T, sum;
struct Eddge {
  int nex, u, v, flow, cost;
  Eddge(int a = -1, int b = 0, int c = 0, int d = 0, int f = 0)
      : nex(a), u(b), v(c), flow(d), cost(f) {}
} edge[maxE];
inline void addEddge(int u, int v, int flow, int cost) {
  edge[cnt] = Eddge(head[u], u, v, flow, cost);
  head[u] = cnt++;
}
inline void _add(int u, int v, int flow, int cost) {
  addEddge(u, v, flow, cost);
  addEddge(v, u, 0, -cost);
}
int pre[maxN], dist[maxN], Flow[maxN];
bool inque[maxN];
queue<int> Q;
bool spfa() {
  memset(pre, -1, sizeof(pre));
  memset(dist, 0x3f3f3f3f, sizeof(dist));
  memset(inque, false, sizeof(inque));
  while (!Q.empty()) Q.pop();
  Q.push(S);
  inque[S] = true;
  dist[S] = 0;
  Flow[S] = 0x3f3f3f3f;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    inque[u] = false;
    for (int i = head[u], v, f, c; ~i; i = edge[i].nex) {
      v = edge[i].v;
      f = edge[i].flow;
      c = edge[i].cost;
      if (f && dist[v] > dist[u] + c) {
        dist[v] = dist[u] + c;
        Flow[v] = min(Flow[u], f);
        pre[v] = i;
        if (!inque[v]) {
          inque[v] = true;
          Q.push(v);
        }
      }
    }
  }
  return pre[T] ^ -1;
}
int EK() {
  int ans = 0;
  while (spfa()) {
    int now = T, las = pre[now];
    while (now) {
      edge[las].flow -= Flow[T];
      edge[las ^ 1].flow += Flow[T];
      now = edge[las].u;
      las = pre[now];
    }
    ans += dist[T] * Flow[T];
  }
  return ans;
}
inline void init() {
  cnt = sum = 0;
  T = N + 1;
  memset(head, -1, sizeof(head));
  memset(pos, 0, sizeof(pos));
}
int main() {
  scanf("%d%d", &N, &K);
  init();
  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++) sum += c[a[i]];
  for (int i = 1; i < N; i++) _add(i, i + 1, K - 1, 0);
  _add(S, 1, K - 1, 0);
  pos[a[1]] = 1;
  for (int i = 2; i <= N; i++) {
    if (pos[a[i]]) {
      if (pos[a[i]] + 1 == i)
        sum -= c[a[i]];
      else
        _add(pos[a[i]] + 1, i, 1, -c[a[i]]);
    }
    pos[a[i]] = i;
  }
  _add(N, T, K - 1, 0);
  printf("%d\n", sum + EK());
  return 0;
}
