#include <bits/stdc++.h>
using namespace std;
const int MAXN = 80;
const int INF = 1e9;
const int MAXGN = 1000100;
const int MAXGM = 1000100;
typedef struct MCMF {
  int n, m;
  int ghead[MAXGN], gnxt[2 * MAXGM], gto[2 * MAXGM], gcap[2 * MAXGM],
      gcost[2 * MAXGM];
  long long d[MAXGN];
  int bck[MAXGN];
  long long pot[MAXGN];
  void init(int _n) {
    n = _n, m = 0;
    for (int i = (0), _for = (n); i < _for; ++i) ghead[i] = -1, pot[i] = 0;
  }
  void addedge(int a, int b, int c, int d) {
    gnxt[m] = ghead[a], ghead[a] = m, gto[m] = b, gcap[m] = c, gcost[m] = d,
    ++m;
    gnxt[m] = ghead[b], ghead[b] = m, gto[m] = a, gcap[m] = 0, gcost[m] = -d,
    ++m;
  }
  pair<int, long long> solve(int s, int t, int lim) {
    for (int i = (0), _for = (n); i < _for; ++i) d[i] = LLONG_MAX, bck[i] = -1;
    d[s] = 0, bck[s] = -2;
    while (true) {
      bool change = false;
      for (int at = (0), _for = (n); at < _for; ++at)
        if (d[at] != LLONG_MAX)
          for (int first = ghead[at]; first != -1; first = gnxt[first])
            if (gcap[first] > 0) {
              int to = gto[first];
              if (d[at] + gcost[first] >= d[to]) continue;
              d[to] = d[at] + gcost[first];
              bck[to] = first ^ 1;
              change = true;
            }
      if (!change) break;
    }
    assert(d[t] != LLONG_MAX);
    for (int i = (0), _for = (n); i < _for; ++i) pot[i] = d[i];
    pair<int, long long> ret = make_pair(0, 0);
    while (ret.first < lim) {
      for (int i = (0), _for = (n); i < _for; ++i)
        d[i] = LLONG_MAX, bck[i] = -1;
      d[s] = 0, bck[s] = -2;
      priority_queue<pair<long long, int> > q;
      q.push(make_pair(-d[s], s));
      while (!q.empty()) {
        long long cost = -q.top().first;
        int at = q.top().second;
        q.pop();
        if (cost > d[at]) continue;
        for (int first = ghead[at]; first != -1; first = gnxt[first])
          if (gcap[first] > 0) {
            int to = gto[first];
            long long rcost = gcost[first] - pot[at] + pot[to];
            if (d[at] + rcost >= d[to]) continue;
            d[to] = d[at] + rcost;
            bck[to] = first ^ 1;
            q.push(make_pair(-d[to], to));
          }
      }
      if (d[t] == LLONG_MAX) break;
      if (d[t] - pot[t] > 0) return ret;
      ++ret.first, ret.second += d[t] - pot[t];
      for (int i = (0), _for = (n); i < _for; ++i)
        if (d[i] != LLONG_MAX) pot[i] -= d[i];
      for (int at = t; at != s; at = gto[bck[at]]) {
        ++gcap[bck[at]];
        --gcap[bck[at] ^ 1];
      }
    }
    return ret;
  }
} MCMF;
MCMF G;
namespace Mcmf {
const int MAXV = 1000100;
const int MAXE = 1000100;
const long long oo = 1e18;
int V, E;
int last[MAXV], how[MAXV];
long long dist[MAXV];
int next[MAXE], from[MAXE], adj[MAXE];
long long cap[MAXE], cost[MAXE];
struct cmpf {
  bool operator()(int a, int b) {
    if (dist[a] != dist[b]) return dist[a] < dist[b];
    return a < b;
  }
};
set<int, cmpf> S;
void init(int n) {
  V = n;
  E = 0;
  for (int i = (0), _for = (V); i < _for; ++i) last[i] = -1;
}
void edge(int first, int second, long long c, long long w) {
  from[E] = first;
  adj[E] = second;
  cap[E] = c;
  cost[E] = +w;
  next[E] = last[first];
  last[first] = E++;
  from[E] = second;
  adj[E] = first;
  cap[E] = 0;
  cost[E] = -w;
  next[E] = last[second];
  last[second] = E++;
}
pair<long long, long long> run(int src, int sink) {
  long long total = 0;
  long long flow = 0;
  for (;;) {
    for (int i = (0), _for = (V); i < _for; ++i) dist[i] = oo;
    dist[src] = 0;
    for (;;) {
      bool done = true;
      for (int first = (0), _for = (V); first < _for; ++first)
        for (int e = last[first]; e != -1; e = next[e]) {
          if (cap[e] == 0) continue;
          int second = adj[e];
          long long val = dist[first] + cost[e];
          if (val < dist[second]) {
            dist[second] = val;
            how[second] = e;
            done = false;
          }
        }
      if (done) break;
    }
    if (dist[sink] >= oo / 2) break;
    long long aug = cap[how[sink]];
    for (int i = sink; i != src; i = from[how[i]]) aug = min(aug, cap[how[i]]);
    for (int i = sink; i != src; i = from[how[i]]) {
      cap[how[i]] -= aug;
      cap[how[i] ^ 1] += aug;
      total += cost[how[i]] * aug;
    }
    flow += aug;
  }
  return {total, flow};
}
}  // namespace Mcmf
int n, k;
int a[MAXN + 5];
int c[MAXN + 5];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = (0), _for = (n); i < _for; ++i) scanf("%d", a + i);
  for (int i = (0), _for = (n); i < _for; ++i) a[i]--;
  for (int i = (0), _for = (n); i < _for; ++i) scanf("%d", c + i);
  int s = n * 2, t = n * 2 + 1;
  G.init(n * 2 + 5);
  Mcmf::init(n * 2 + 5);
  for (int i = (0), _for = (n); i < _for; ++i) {
    G.addedge(s, i * 2, 1, c[a[i]]);
    G.addedge(i * 2, i * 2 + 1, 1, -INF);
    G.addedge(i * 2 + 1, t, 1, 0);
    for (int j = (i + 1), _for = (n); j < _for; ++j) {
      if (a[i] == a[j])
        G.addedge(i * 2 + 1, j * 2, 1, 0);
      else
        G.addedge(i * 2 + 1, j * 2, 1, c[a[j]]);
    }
    Mcmf::edge(s, i * 2, 1, c[a[i]]);
    Mcmf::edge(i * 2, i * 2 + 1, 1, -INF);
    Mcmf::edge(i * 2 + 1, t, 1, 0);
    for (int j = (i + 1), _for = (n); j < _for; ++j) {
      if (a[i] == a[j])
        Mcmf::edge(i * 2 + 1, j * 2, 1, 0);
      else
        Mcmf::edge(i * 2 + 1, j * 2, 1, c[a[j]]);
    }
  }
  Mcmf::edge(n * 2 + 2, s, k, 0);
  G.addedge(n * 2 + 2, s, k, 0);
  auto ans = G.solve(n * 2 + 2, t, k);
  long long first = ans.second;
  first = (first % INF + INF) % INF;
  printf("%lld\n", first);
  return 0;
}
