#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, k = 1;
  char ch = getchar();
  while (ch<'0' | ch> '9') ch == '-' ? k = -1 : 0, ch = getchar();
  while (ch > 47 & ch <= '9') s = s * 10 + (ch ^ 48), ch = getchar();
  return s * k;
}
const int N = 100;
struct edges {
  int v, cap, cost, re;
  edges *last;
} edge[N * N], *head[N], *fm[N];
int cnt;
inline void push(int u, int v, int cap, int cost) {
  ++cnt, edge[cnt] = (edges){v, cap, cost, cnt + 1, head[u]},
         head[u] = edge + cnt;
  ++cnt, edge[cnt] = (edges){u, 0, -cost, cnt - 1, head[v]},
         head[v] = edge + cnt;
}
int S, T, d[N], q[N], n, k, vis[N];
inline bool spfa() {
  int l, r;
  l = r = 0;
  memset(d, 0x3f, sizeof d);
  d[q[r++] = S] = 0;
  vis[S] = true;
  while (l ^ r) {
    int x = q[l++];
    l == N ? l = 0 : 0;
    for (edges *i = head[x]; i; i = i->last)
      if (i->cap) {
        if (d[x] + i->cost < d[i->v]) {
          d[i->v] = d[x] + i->cost, fm[i->v] = i;
          if (!vis[i->v]) q[r++] = i->v, vis[i->v] = true, r == N ? r = 0 : 0;
        }
      }
    vis[x] = false;
  }
  return d[T] != d[T + 1];
}
inline int mcmf() {
  int ret = 0;
  while (spfa()) {
    int flow = 0x7fffffff;
    for (edges *i = fm[T]; i; i = fm[edge[i->re].v]) flow = min(flow, i->cap);
    for (edges *i = fm[T]; i; i = fm[edge[i->re].v])
      i->cap -= flow, edge[i->re].cap += flow;
    ret += flow * d[T];
  }
  return ret;
}
int a[N], c[N], pos[N];
int main() {
  n = read(), k = read() - 1;
  T = n + 1;
  register int i;
  for (i = 1; i <= n; ++i) a[i] = read();
  for (i = 1; i <= n; ++i) c[i] = read();
  push(S, 1, k, 0), push(n, T, k, 0);
  for (i = 1; i < n; ++i) push(i, i + 1, k, 0);
  int ans = 0;
  for (i = 1; i <= n; ++i) {
    ans += c[a[i]];
    if (pos[a[i]]) {
      if (pos[a[i]] == i - 1)
        ans -= c[a[i]];
      else
        push(pos[a[i]] + 1, i, 1, -c[a[i]]);
    }
    pos[a[i]] = i;
  }
  printf("%d\n", ans + mcmf());
}
