#include <bits/stdc++.h>
using namespace std;
const int N = 505, M = 1e5, INF = 1e9;
vector<pair<int, int>> v[N];
int fl[M], cp[M], wt[M], d[N], anc[N], pe[N];
int z = 0, s = N - 2, t = N - 1, n, m, x;
bool inq[N];
string cr;
bool bellman() {
  queue<int> q;
  q.push(s);
  fill(d, d + N, -1);
  d[s] = 0;
  inq[s] = 1;
  while (!q.empty()) {
    int node = q.front();
    inq[node] = 0;
    q.pop();
    for (auto p : v[node]) {
      int to = p.first, num = p.second, val = d[node] + wt[num];
      if (fl[num] < cp[num] && val > d[to]) {
        d[to] = val;
        anc[to] = node;
        pe[to] = num;
        if (!inq[to]) {
          q.push(to);
          inq[to] = 1;
        }
      }
    }
  }
  return d[t] != -1;
}
int maxCostMaxFlow() {
  int flow = 0, sum = 0;
  while (bellman()) {
    int node = t;
    while (node != s) {
      int num = pe[node];
      sum += wt[num];
      fl[num]++;
      fl[num ^ 1]--;
      node = anc[node];
    }
    flow++;
    if (flow == x) break;
  }
  return sum;
}
void addEdge(int from, int to, int cap, int w) {
  cp[z] = cap;
  wt[z] = w;
  v[from].push_back({to, z++});
  wt[z] = -w;
  v[to].push_back({from, z++});
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> cr >> m;
  cr.push_back('#');
  n++;
  for (int i = 0; i < m; i++) {
    int p;
    string g;
    cin >> g >> p;
    for (int j = 0; j <= n - (int)g.size(); j++) {
      if (cr.substr(j, g.size()) == g) {
        addEdge(j, j + g.size(), 1, p);
      }
    }
  }
  cin >> x;
  for (int i = 0; i < n - 1; i++) {
    addEdge(i, i + 1, INF, 0);
  }
  addEdge(s, 0, INF, 0);
  addEdge(n - 1, t, INF, 0);
  cout << maxCostMaxFlow();
  return 0;
}
