#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}
template <typename T, typename... U>
inline void read(T& x, U&... y) {
  read(x), read(y...);
}
const int N = 2e2 + 10, M = 1e3 + 10, INF = 0x7fffffff;
int n, m, S, T, MC, MF, K, p = 1;
int head[N], from[N], last[N], F[N], G[N], A[N], C[N];
bool vis[N];
struct Edge {
  int to, last, cap, flow, w;
  Edge() {}
  Edge(int a, int b, int c, int d) : to(a), last(b), cap(c), w(d) { flow = 0; };
} edge[M << 1];
void ADD(int a, int b, int c, int d) {
  edge[++p] = Edge(b, head[a], c, d);
  head[a] = p;
  edge[++p] = Edge(a, head[b], 0, -d);
  head[b] = p;
}
bool SPFA() {
  queue<int> Q;
  for (int i = 1; i <= T; ++i) G[i] = INF;
  from[S] = 0;
  F[S] = INF;
  G[S] = 0;
  vis[S] = true;
  Q.push(S);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = head[u]; i; i = edge[i].last) {
      int v = edge[i].to;
      if (edge[i].cap > edge[i].flow && G[v] > G[u] + edge[i].w) {
        G[v] = G[u] + edge[i].w;
        from[v] = u;
        last[v] = i;
        F[v] = min(F[u], edge[i].cap - edge[i].flow);
        if (!vis[v]) vis[v] = true, Q.push(v);
      }
    }
    vis[u] = false;
  }
  return G[T] != INF;
}
void Update(int f, int g) {
  for (int i = T; i != S; i = from[i]) {
    int e = last[i];
    edge[e].flow += f;
    edge[e ^ 1].flow -= f;
  }
  MC += f * g;
  MF += f;
}
int main() {
  read(n, K);
  S = n * 2 + 1;
  T = S + 1;
  for (int i = 1; i <= n; ++i) read(A[i]);
  for (int i = 1; i <= n; ++i) read(C[i]);
  for (int i = 1; i <= n; ++i) {
    ADD(S, i, 1, C[A[i]]);
    ADD(i, i + n, 1, 0);
    ADD(i + n, T, 1, 0);
    ADD(i, i + 1, K - 1, 0);
    if (last[A[i]]) ADD(i - 1, last[A[i]] + n, 1, -C[A[i]]);
    last[A[i]] = i;
  }
  while (SPFA()) Update(F[T], G[T]);
  printf("%d\n", MC);
  return 0;
}
