#include <bits/stdc++.h>
using namespace std;
const int M = 100005, N = 505;
int n, m, edgenum = 1, S, T, ans, head[N], vet[M], Next[M], val[M], flow[M],
          id[N], pre[N], dis[N];
char s1[N], s2[N];
bool vis[N];
queue<int> q;
void add(int u, int v, int w, int p) {
  edgenum++;
  Next[edgenum] = head[u];
  vet[edgenum] = v;
  val[edgenum] = w;
  flow[edgenum] = p;
  head[u] = edgenum;
  edgenum++;
  Next[edgenum] = head[v];
  vet[edgenum] = u;
  val[edgenum] = -w;
  flow[edgenum] = 0;
  head[v] = edgenum;
}
bool bfs() {
  memset(dis, 0xc0, sizeof(dis));
  dis[S] = 0, q.push(S);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int e = head[u]; e; e = Next[e]) {
      int v = vet[e];
      if (dis[v] < dis[u] + val[e] && flow[e]) {
        dis[v] = dis[u] + val[e];
        id[v] = e, pre[v] = u;
        if (!vis[v]) q.push(v), vis[v] = 1;
      }
    }
  }
  return dis[T] > 0;
}
int main() {
  scanf("%d%s%d", &n, s1 + 1, &m);
  for (int i = 1; i <= m; i++) {
    int x;
    scanf("%s%d", s2, &x);
    int l = strlen(s2);
    for (int j = 1; j <= n - l + 1; j++) {
      int k;
      for (k = 0; k < l; k++)
        if (s1[j + k] != s2[k]) break;
      if (k == l) add(j, j + l, x, 1);
    }
  }
  int p;
  scanf("%d", &p);
  for (int i = 0; i <= n; i++) add(i, i + 1, 0, p);
  S = 0, T = n + 1;
  while (bfs()) {
    ans += dis[T];
    for (int i = T; i != S; i = pre[i]) flow[id[i]]--, flow[id[i] ^ 1]++;
  }
  printf("%d", ans);
  return 0;
}
