#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, S, T, ans;
int to[100000], nxt[100000], head[510], cost[100000], flow[100000], pe[510],
    pv[510], dis[510], inq[510];
char s1[510], s2[510];
queue<int> q;
inline void add(int a, int b, int c, int d) {
  to[cnt] = b, cost[cnt] = c, flow[cnt] = d, nxt[cnt] = head[a],
  head[a] = cnt++;
  to[cnt] = a, cost[cnt] = -c, flow[cnt] = 0, nxt[cnt] = head[b],
  head[b] = cnt++;
}
inline int bfs() {
  memset(dis, 0xc0, sizeof(dis));
  dis[S] = 0, q.push(S);
  int i, u;
  while (!q.empty()) {
    u = q.front(), inq[u] = 0, q.pop();
    for (i = head[u]; i != -1; i = nxt[i])
      if (dis[to[i]] < dis[u] + cost[i] && flow[i]) {
        dis[to[i]] = dis[u] + cost[i], pe[to[i]] = i, pv[to[i]] = u;
        if (!inq[to[i]]) q.push(to[i]), inq[to[i]] = 1;
      }
  }
  return dis[T] > 0;
}
int main() {
  scanf("%d%s%d", &n, s1 + 1, &m);
  int i, j, k, a, b;
  memset(head, -1, sizeof(head));
  for (i = 1; i <= m; i++) {
    scanf("%s%d", s2, &b), a = strlen(s2);
    for (j = 1; j + a - 1 <= n; j++) {
      for (k = 0; k < a; k++)
        if (s1[j + k] != s2[k]) break;
      if (k == a) add(j, j + a, b, 1);
    }
  }
  scanf("%d", &a);
  for (i = 0; i <= n; i++) add(i, i + 1, 0, a);
  S = 0, T = n + 1;
  while (bfs()) {
    ans += dis[T];
    for (i = T; i != S; i = pv[i]) flow[pe[i]]--, flow[pe[i] ^ 1]++;
  }
  printf("%d", ans);
  return 0;
}
