#include <bits/stdc++.h>
using namespace std;
deque<int> q;
int n, k, s, t, cnt, ans;
int a[205], c[205], Last[205];
int dis[205], vis[205], cur[205], head[205];
int w[2005], to[2005], cost[2005], Next[2005];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void add(int u, int v, int p, int c) {
  w[++cnt] = p;
  to[cnt] = v;
  cost[cnt] = c;
  Next[cnt] = head[u];
  head[u] = cnt;
}
int spfa() {
  memset(dis, 0x3f, sizeof dis);
  memcpy(cur, head, sizeof cur);
  q.push_back(s);
  dis[s] = 0;
  vis[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    vis[u] = 0;
    if (!q.empty() && dis[q.front()] > dis[q.back()]) swap(q.front(), q.back());
    for (register int i = head[u]; ~i; i = Next[i]) {
      int v = to[i];
      if (w[i] && dis[v] > dis[u] + cost[i]) {
        dis[v] = dis[u] + cost[i];
        if (!vis[v]) {
          vis[v] = 1;
          q.push_back(v);
          if (!q.empty() && dis[q.front()] > dis[q.back()])
            swap(q.front(), q.back());
        }
      }
    }
  }
  return dis[t] != dis[t + 1];
}
int dfs(int u, int flow) {
  if (!flow || u == t) return flow;
  int res = 0;
  vis[u] = 1;
  for (register int i = head[u]; ~i; i = Next[i]) {
    int v = to[i];
    if (w[i] && !vis[v] && dis[v] == dis[u] + cost[i]) {
      int d = dfs(v, min(w[i], flow));
      res += d;
      flow -= d;
      w[i] -= d;
      w[i ^ 1] += d;
      ans += d * cost[i];
      if (!flow) break;
    }
  }
  vis[u] = 0;
  return res;
}
void Dinic() {
  while (spfa()) {
    while (dfs(s, 1000007))
      ;
  }
  return;
}
int main() {
  cnt = -1;
  memset(head, -1, sizeof head);
  n = read();
  k = read();
  s = 0;
  t = n + n + 1;
  for (register int i = 1; i <= n; ++i) a[i] = read();
  for (register int i = 1; i <= n; ++i) c[i] = read();
  for (register int i = 1; i <= n; ++i) {
    add(n + i, t, 1, 0);
    add(t, n + i, 0, 0);
  }
  for (register int i = 1; i <= n; ++i) {
    add(0 + i, n + i, 1, 0);
    add(n + i, 0 + i, 0, 0);
  }
  for (register int i = 1; i <= n; ++i) {
    add(s, 0 + i, 1, c[a[i]]);
    add(0 + i, s, 0, c[a[i]]);
  }
  for (register int i = 2; i <= n; ++i) {
    add(0 + i - 1, 0 + i, k - 1, 0);
    add(0 + i, 0 + i - 1, 0 - 0, 0);
  }
  for (register int i = 1; i <= n; ++i) {
    if (Last[a[i]]) {
      add(0 + i - 1, n + Last[a[i]], 1, -c[a[i]]);
      add(n + Last[a[i]], 0 + i - 1, 0, +c[a[i]]);
    }
    Last[a[i]] = i;
  }
  Dinic();
  printf("%d\n", ans);
  return 0;
}
