#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T& a, const T& b) {
  return a < b ? (a = b, true) : false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  return b < a ? (a = b, true) : false;
}
int N, K, S, T;
const int MAX_N = 80, MAX_V = MAX_N * 2 + 2;
vector<int> A, C;
struct edge {
  edge(int a, int b, int c, int d) {
    to = a;
    rev = b;
    cap = c;
    cost = d;
  }
  int to, rev, cap, cost;
};
vector<edge> G[MAX_V];
long long minCost[MAX_V];
int prevv[MAX_V], preve[MAX_V];
const long long INF = 1e9;
void add_edge(int from, int to, int cap, int cost) {
  G[from].push_back(edge(to, G[to].size(), cap, cost));
  G[to].push_back(edge(from, G[from].size() - 1, 0, -cost));
}
int min_cost_max_flow() {
  long long res = INF * N;
  while (true) {
    fill(minCost, minCost + T + 1, INF * INF);
    minCost[S] = 0;
    while (true) {
      bool update = false;
      for (int i = (int)(0); i < (int)(T + 1); i++)
        for (int j = (int)(0); j < (int)(G[i].size()); j++) {
          edge& e = G[i][j];
          if (e.cap > 0 && chmin(minCost[e.to], minCost[i] + e.cost)) {
            prevv[e.to] = i;
            preve[e.to] = j;
            update = true;
          }
        }
      if (update == false) break;
    }
    if (minCost[T] == INF * INF) return res;
    int f = INF;
    for (int v = T; v != S; v = prevv[v]) {
      chmin(f, G[prevv[v]][preve[v]].cap);
    }
    res += f * minCost[T];
    for (int v = T; v != S; v = prevv[v]) {
      edge& e = G[prevv[v]][preve[v]];
      e.cap -= f;
      G[e.to][e.rev].cap += f;
    }
  }
}
int main() {
  scanf("%d%d", &N, &K);
  S = N * 2;
  T = S + 1;
  A.assign(N, 0);
  C.assign(N, 0);
  for (int i = (int)(0); i < (int)(N); i++) {
    scanf("%d", &A[i]);
    A[i]--;
  }
  for (int i = (int)(0); i < (int)(N); i++) {
    scanf("%d", &C[i]);
  }
  add_edge(S, 0, K, 0);
  for (int i = (int)(0); i < (int)(N - 1); i++) {
    add_edge(i + N, i + 1, K, 0);
  }
  add_edge(N - 1 + N, T, K, 0);
  for (int i = (int)(0); i < (int)(N); i++) {
    add_edge(i, i + N, 1, -INF);
    add_edge(i, i + N, INF, 0);
  }
  vector<int> last(N, -1);
  for (int i = N - 1; i >= 0; i--) {
    if (last[A[i]] != -1) {
      add_edge(i + N, last[A[i]], 1, -C[A[i]]);
    }
    last[A[i]] = i;
  }
  long long ans = min_cost_max_flow();
  for (int i = (int)(0); i < (int)(N); i++) {
    ans += C[A[i]];
  }
  printf("%lld\n", ans);
  return 0;
}
