#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
inline int read() {
  int sum = 0, p = 1;
  char ch = getchar();
  while (!(('0' <= ch && ch <= '9') || ch == '-')) ch = getchar();
  if (ch == '-') p = -1, ch = getchar();
  while ('0' <= ch && ch <= '9') sum = sum * 10 + ch - 48, ch = getchar();
  return sum * p;
}
const int maxn = 200;
const int inf = 0x3f3f3f3f;
struct node {
  int v, next, w, cost;
};
node e[maxn * maxn * 4];
int cnt = 1, start[maxn];
inline void addedge(int u, int v, int w, int cost) {
  e[++cnt] = (node){v, start[u], w, cost};
  start[u] = cnt;
}
inline void Addedge(int u, int v, int w, int cost) {
  addedge(u, v, w, cost);
  addedge(v, u, 0, -cost);
}
int n, k, a[maxn], c[maxn], S, T, tot;
int num[maxn][2];
int ST;
inline void init() {
  n = read();
  k = read();
  for (int i = (1), _end_ = (n); i <= _end_; i++) a[i] = read();
  for (int i = (1), _end_ = (n); i <= _end_; i++) c[i] = read();
  S = ++tot;
  T = ++tot;
  ST = ++tot;
  Addedge(S, ST, k, 0);
  for (int i = (1), _end_ = (n); i <= _end_; i++) {
    num[i][0] = ++tot, num[i][1] = ++tot;
    Addedge(num[i][0], num[i][1], 1, -inf);
    Addedge(num[i][1], T, 1, 0);
  }
  for (int i = (0), _end_ = (n - 1); i <= _end_; i++)
    for (int j = (i + 1), _end_ = (n); j <= _end_; j++) {
      Addedge(i ? num[i][1] : ST, num[j][0], 1,
              i && a[i] == a[j] ? 0 : c[a[j]]);
    }
}
long long dist[maxn];
int pre[maxn], vis[maxn];
inline long long min_cost(int S, int T) {
  queue<int> q;
  long long ans = 0;
  while (1) {
    for (int i = (1), _end_ = (tot); i <= _end_; i++)
      dist[i] = 1ll << 60, pre[i] = vis[i] = 0;
    q.push(S);
    dist[S] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      vis[u] = 0;
      for (int i = start[(u)]; i; i = e[i].next) {
        int v = e[i].v;
        if (dist[v] > dist[u] + e[i].cost && e[i].w) {
          dist[v] = dist[u] + e[i].cost;
          pre[v] = i;
          if (!vis[v]) q.push(v), vis[v] = 1;
        }
      }
    }
    if (dist[T] == (1ll << 60)) break;
    if (dist[T] >= 0) break;
    int flow = inf;
    for (int i = pre[T]; i; i = pre[e[i ^ 1].v]) chkmin(flow, e[i].w);
    for (int i = pre[T]; i; i = pre[e[i ^ 1].v])
      e[i].w -= flow, e[i ^ 1].w += flow;
    ans += 1ll * flow * dist[T];
  }
  return ans;
}
inline void doing() { printf("%lld\n", min_cost(S, T) + 1ll * n * inf); }
int main() {
  init();
  doing();
  return 0;
}
