#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
int N, a[169], c[169], K;
long long int M = -10000000000000LL;
int ned, prv[169], first[169];
long long int cap[20009], cost[20009], to[20009], nxt[20009], dist[169],
    pot[169];
void init() {
  memset(first, -1, sizeof first);
  ned = 0;
}
void add(int u, int v, long long int f, long long int c) {
  to[ned] = v, cap[ned] = f;
  cost[ned] = c, nxt[ned] = first[u];
  first[u] = ned++;
  to[ned] = u, cap[ned] = 0;
  cost[ned] = -c, nxt[ned] = first[v];
  first[v] = ned++;
}
bool dijkstra(int s, int t) {
  memset(prv, -1, sizeof prv);
  for (int i = 0; i < N; i++) dist[i] = 1000000000000000000LL;
  set<pair<long long int, int> > q;
  q.insert(make_pair(0LL, s));
  dist[s] = prv[s] = 0;
  int u, v;
  while (!q.empty()) {
    u = q.begin()->second;
    q.erase(q.begin());
    for (int e = first[u]; e != -1; e = nxt[e]) {
      if (cap[e] <= 0) continue;
      v = to[e];
      long long int new_dist = dist[u] + cost[e] + pot[u] - pot[v];
      if (new_dist < dist[v]) {
        q.erase(make_pair(dist[v], v));
        dist[v] = new_dist;
        prv[v] = e;
        q.insert(make_pair(new_dist, v));
      }
    }
  }
  return prv[t] != -1;
}
inline long long int augment(int s, int t) {
  for (int i = t; i != s; i = to[prv[i] ^ 1]) {
    cap[prv[i]]--;
    cap[prv[i] ^ 1]++;
  }
  --K;
  long long int flowCost = dist[t] - pot[s] + pot[t];
  for (int i = 0; i < N; i++)
    if (prv[i] != -1) pot[i] += dist[i];
  return flowCost;
}
long long int mincostmaxflow(int s, int t) {
  long long int flowCost = 0;
  memset(pot, 0, sizeof(pot));
  while (K > 0 && dijkstra(s, t)) {
    flowCost += augment(s, t);
  }
  return flowCost;
}
int main() {
  set<int> v;
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
    v.insert(a[i]);
  }
  for (int i = 1; i < N + 1; ++i) scanf("%d", &c[i]);
  init();
  K = min(K, (int)v.size());
  for (int i = 0; i < N; ++i) {
    add(0, 2 * i + 1, 1, c[a[i]]);
    add(2 * i + 1, 2 * i + 2, 1, M);
    add(2 * i + 2, 2 * N + 1, 1, 0);
    for (int j = i + 1; j < N; ++j) {
      if (a[i] != a[j])
        add(2 * i + 2, 2 * j + 1, 1, c[a[j]]);
      else
        add(2 * i + 2, 2 * j + 1, 1, 0);
    }
  }
  long long int n = N;
  N = 2 * N + 2;
  printf("%lld\n", mincostmaxflow(0, N - 1) - M * n);
}
