#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
int n, k, a[210], cnt, dst;
long long c[210], ans;
struct edge {
  int to, cap;
  long long cost;
  edge(int to = 0, int cap = 0, long long cost = 0)
      : to(to), cap(cap), cost(cost){};
} ee[100010];
vector<int> V[210];
void addedge(int x, int y, int cap, long long cost) {
  ee[cnt] = edge(y, cap, cost);
  V[x].push_back(cnt++);
  ee[cnt] = edge(x, 0, -cost);
  V[y].push_back(cnt++);
}
int prv[210], vis[210];
long long dist[210];
long long SPFA() {
  queue<int> Q;
  while (!Q.empty()) Q.pop();
  for (int i = 0; i <= dst; i++) {
    vis[i] = 0;
    prv[i] = -1;
    dist[i] = inf;
  }
  dist[0] = 0;
  Q.push(0);
  vis[0] = 1;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    vis[x] = 0;
    for (int i = 0; i < V[x].size(); i++) {
      int y = V[x][i];
      int z = ee[y].to;
      if (dist[z] > dist[x] + ee[y].cost && ee[y].cap > 0) {
        if (!vis[z]) {
          Q.push(z);
          vis[z] = 1;
        }
        dist[z] = dist[x] + ee[y].cost;
        prv[z] = y;
      }
    }
  }
  if (prv[dst] == -1) {
    return 0;
  }
  int x = dst;
  while (x) {
    int y = prv[x];
    ee[y].cap--;
    ee[y ^ 1].cap++;
    x = ee[y ^ 1].to;
  }
  return dist[dst];
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  dst = 2 * n + 1;
  for (int i = 1; i <= n; i++) {
    ans += c[a[i]];
    addedge(0, i + n, 1, 0);
    addedge(i, dst, 1, 0);
    addedge(n + i, i, 1, -inf);
    for (int j = i + 1; j <= n; j++) {
      if (a[i] == a[j])
        addedge(i, j + n, 1, -c[a[i]]);
      else
        addedge(i, j + n, 1, 0);
    }
  }
  for (int step = 1; step <= k; step++) {
    long long add = SPFA();
    if (add >= 0) break;
    ans += add;
  }
  ans += n * inf;
  printf("%I64d\n", ans);
}
