#include <bits/stdc++.h>
using namespace std;
struct arr {
  int to, ne, f, c;
} e[10 * 506 * 506];
char s[506 * 506], c[506 * 506];
bool f[506 * 506];
int n, m, S, T, x, y, l, cnt, ans, head[506 * 506], q[10 * 506 * 506],
    p[506 * 506], fr[506 * 506], d[506 * 506], minf[506 * 506];
inline int read() {
  int x = 0, c = getchar(), f = 1LL;
  while (c < '0' || c > '9') f = (c == '-' ? -f : f), c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 1LL) + (x << 3) + c - 48, c = getchar();
  return f > 0 ? x : -x;
}
void print(long long x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 + 48);
}
inline void add(int x, int y, int f, int c) {
  e[++cnt].to = y;
  e[cnt].f = f;
  e[cnt].c = c;
  e[cnt].ne = head[x];
  head[x] = cnt;
  e[++cnt].to = x;
  e[cnt].f = 0;
  e[cnt].c = -c;
  e[cnt].ne = head[y];
  head[y] = cnt;
}
void spfa() {
  memset(f, 0, sizeof f);
  memset(d, -1, sizeof d);
  int h = 0, t = 1;
  q[1] = S;
  f[S] = 1;
  d[S] = p[S] = fr[S] = 0;
  minf[S] = 1000000007;
  while (h < t) {
    int x = q[++h];
    for (int i = head[x]; i; i = e[i].ne)
      if (e[i].f) {
        int y = e[i].to;
        if (d[y] < d[x] + e[i].c) {
          d[y] = d[x] + e[i].c;
          p[y] = i;
          fr[y] = x;
          minf[y] = min(minf[x], e[i].f);
          if (!f[y]) f[y] = 1, q[++t] = y;
        }
      }
    f[x] = 0;
  }
}
int main() {
  n = read();
  scanf("%s", s + 1);
  m = read();
  S = n + 3;
  T = n + 2;
  cnt = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%s", c + 1);
    x = read();
    l = strlen(c + 1);
    for (int j = 1; j + l - 1 <= n; j++) {
      bool flag = 1;
      for (int k = 1; k <= l; k++)
        if (c[k] != s[j + k - 1]) {
          flag = 0;
          break;
        }
      if (flag) add(j, j + l, 1, x);
    }
  }
  x = read();
  add(S, 1, x, 0);
  add(n + 1, T, 1000000007, 0);
  for (int i = 1; i <= n; i++) add(i, i + 1, 1000000007, 0);
  while (1) {
    spfa();
    if (d[T] < 0) break;
    ans += d[T];
    for (int i = T; i; i = fr[i])
      e[p[i]].f -= minf[T], e[p[i] ^ 1].f += minf[T];
  }
  print(ans);
}
