#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e16;
struct Edge {
  long long x, y, c, w, f;
  Edge() {}
  Edge(long long _x, long long _y, long long _c, long long _w, long long _f)
      : x(_x), y(_y), c(_c), w(_w), f(_f) {}
};
struct MincostFlow {
  long long n, totCost, totFlow, s, t;
  vector<vector<long long>> adj;
  vector<long long> inq, dist, trace;
  vector<Edge> EdgeList;
  queue<long long> q;
  MincostFlow() {}
  MincostFlow(long long _n) {
    this->n = _n;
    adj.assign(n + 5, vector<long long>(0, 0));
    EdgeList.clear();
  }
  void addEdge(long long u, long long v, long long c, long long w) {
    adj[u].push_back((long long)EdgeList.size());
    EdgeList.push_back(Edge(u, v, c, w, 0));
    adj[v].push_back((long long)EdgeList.size());
    EdgeList.push_back(Edge(v, u, 0, -w, 0));
  }
  bool FordBellman(long long s, long long t) {
    inq.assign(n + 5, false);
    dist.assign(n + 5, oo);
    trace.assign(n + 5, -1);
    while (!q.empty()) q.pop();
    q.push(s);
    inq[s] = true;
    dist[s] = 0;
    while (!q.empty()) {
      long long u = q.front();
      q.pop();
      inq[u] = false;
      for (long long id : adj[u]) {
        Edge e = EdgeList[id];
        if (e.c == e.f) continue;
        long long v = e.y;
        if (dist[v] > dist[u] + e.w) {
          trace[v] = id;
          dist[v] = dist[u] + e.w;
          if (!inq[v]) {
            q.push(v);
            inq[v] = 1;
          }
        }
      }
    }
    return (dist[t] != oo);
  }
  void solve() {
    totCost = totFlow = 0;
    while (FordBellman(s, t)) {
      long long delta = oo;
      for (long long u = t; u != s; u = EdgeList[trace[u]].x) {
        Edge e = EdgeList[trace[u]];
        delta = min(delta, e.c - e.f);
      }
      for (long long u = t; u != s; u = EdgeList[trace[u]].x) {
        EdgeList[trace[u]].f += delta;
        EdgeList[trace[u] ^ 1].f -= delta;
      }
      totFlow += delta;
      totCost += dist[t] * delta;
    }
  }
};
const long long N = 105;
long long a[N], c[N], cnt[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  long long distinct = 0;
  for (long long i = 1; i <= n; ++i)
    if (cnt[i]) distinct++;
  k = min(k, distinct);
  for (long long i = 1; i <= n; ++i) cin >> c[i];
  MincostFlow Solver(2 * n + 3);
  long long s = 2 * n + 1;
  Solver.s = 2 * n + 2;
  Solver.t = Solver.s + 1;
  Solver.addEdge(Solver.s, s, k, 0);
  for (long long i = 1; i <= n; ++i) {
    Solver.addEdge(2 * i - 1, 2 * i, 1, -oo);
    Solver.addEdge(s, 2 * i - 1, 1, c[a[i]]);
    Solver.addEdge(2 * i, Solver.t, 1, 0);
    for (long long j = i + 1; j <= n; ++j)
      if (a[i] == a[j]) {
        Solver.addEdge(2 * i, 2 * j - 1, 1, 0);
      } else
        Solver.addEdge(2 * i, 2 * j - 1, 1, c[a[j]]);
  }
  Solver.solve();
  cout << Solver.totCost + n * oo << endl;
  return 0;
}
