#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void in(T &x) {
  x = 0;
  short f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
  x *= f;
}
template <class T>
inline void out(T x, const char c = '\n') {
  static short st[30];
  short m = 0;
  if (x < 0) putchar('-'), x = -x;
  do st[++m] = x % 10, x /= 10;
  while (x);
  while (m) putchar(st[m--] | '0');
  putchar(c);
}
template <class T, class... Args>
inline void in(T &x, Args &...args) {
  in(x);
  in(args...);
}
template <class T, class... Args>
inline void out(const T &x, const Args &...args) {
  out(x, ' ');
  out(args...);
}
template <class T>
inline void prt(T a[], int n) {
  for (register int i = 0; i < n; ++i) out(a[i], ' ');
  putchar('\n');
}
template <class T>
inline void clr(T a[], int n) {
  memset(a, 0, sizeof(T) * n);
}
template <class T>
inline void clr(T *a, T *b) {
  memset(a, 0, sizeof(T) * (b - a));
}
template <class T>
inline bool ckmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline bool ckmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
namespace i207M {
const int inf = 1e9, Max = 2e7;
int head[170], cnte = 1, v[50000], nx[50000], c[50000], w[50000];
inline void adde(int uu, int vv, int ww, int cc) {
  v[++cnte] = vv, nx[cnte] = head[uu], head[uu] = cnte, w[cnte] = ww,
  c[cnte] = cc;
  v[++cnte] = uu, nx[cnte] = head[vv], head[vv] = cnte, w[cnte] = 0,
  c[cnte] = -cc;
}
int S, T;
int f[170], d[170], pe[170];
bool spfa() {
  static queue<int> q;
  memset(f, 0, sizeof(f)), memset(d, 0x3f, sizeof(d));
  d[S] = 0, f[S] = inf, q.push(S);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (register int i = head[x]; i; i = nx[i])
      if (w[i] && d[v[i]] > d[x] + c[i]) {
        d[v[i]] = d[x] + c[i];
        f[v[i]] = min(f[x], w[i]);
        pe[v[i]] = i;
        q.push(v[i]);
      }
  }
  if (!f[T] || d[T] > 0) return 0;
  int x = T;
  while (x != S) {
    int e = pe[x];
    w[e] -= f[T], w[e ^ 1] += f[T];
    x = v[e ^ 1];
  }
  return 1;
}
int EK() {
  int ans = 0;
  while (spfa()) ans += f[T] * d[T];
  return ans;
}
int n, K;
int a[170], cst[170];
signed main() {
  in(n, K);
  for (register int i = 1; i <= n; ++i) in(a[i]);
  for (register int i = 1; i <= n; ++i) in(cst[i]);
  int tot = 2 * n;
  S = ++tot, T = ++tot;
  adde(S, ++tot, K, 0);
  for (register int i = 1; i <= n; ++i) {
    adde(tot, 2 * i - 1, 1, cst[a[i]]);
    adde(2 * i - 1, 2 * i, 1, -Max);
    adde(2 * i, T, 1, 0);
  }
  for (register int i = 1; i <= n; ++i)
    for (register int j = i + 1; j <= n; ++j)
      if (a[i] == a[j])
        adde(2 * i, 2 * j - 1, 1, 0);
      else
        adde(2 * i, 2 * j - 1, 1, cst[a[j]]);
  int ans = EK() + Max * n;
  out(ans);
  return 0;
}
}  // namespace i207M
signed main() {
  i207M::main();
  return 0;
}
