#include <bits/stdc++.h>
const int maxn = 167;
const int maxm = 807;
using namespace std;
int n, k, s, t;
int a[maxn];
int c[maxn];
int p[maxn];
int to[maxm];
int cap[maxm];
int val[maxm];
int nex[maxm];
int last[maxn], cnt = 1;
int dis[maxn];
int vis[maxn];
int pre[maxn];
int flow[maxn];
int e[maxn];
inline void add(int x, int y, int z, int zz) {
  to[++cnt] = y;
  cap[cnt] = z;
  val[cnt] = zz;
  nex[cnt] = last[x];
  last[x] = cnt;
}
inline void add_edge(int x, int y, int z, int zz) {
  add(x, y, z, zz);
  add(y, x, 0, -zz);
}
inline int spfa() {
  memset(dis, 0x3f, sizeof dis);
  memset(vis, 0, sizeof vis);
  memset(pre, 0, sizeof pre);
  memset(flow, 0, sizeof flow);
  queue<int> q;
  q.push(s);
  dis[s] = 0;
  vis[s] = 1;
  flow[s] = 1e9;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = last[x]; i; i = nex[i]) {
      int y = to[i];
      if (cap[i] > 0 && dis[x] + val[i] < dis[y]) {
        dis[y] = dis[x] + val[i];
        e[y] = i;
        pre[y] = x;
        flow[y] = min(flow[x], cap[i]);
        if (!vis[y]) {
          vis[y] = 1;
          q.push(y);
        }
      }
    }
    vis[x] = 0;
  }
  return flow[t];
}
inline int mcmf() {
  int ans = 0;
  while (int d = spfa()) {
    int x = t;
    while (x) {
      int i = e[x];
      cap[i] -= d;
      cap[i ^ 1] += d;
      ans += d * val[i];
      x = pre[x];
    }
  }
  return ans;
}
int main(void) {
  cin >> n >> k;
  t = n << 1 | 1;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1; i <= n; i++) {
    add_edge(s, i, 1, c[a[i]]);
    add_edge(i, i + n, 1, 0);
    add_edge(i + n, t, 1, 0);
    if (p[a[i]]) add_edge(i - 1, p[a[i]] + n, 1, -c[a[i]]);
    if (i < n) add_edge(i, i + 1, k - 1, 0);
    p[a[i]] = i;
  }
  cout << mcmf() << endl;
  return 0;
}
