#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 10, maxm = 200 * maxn, lg = 10, M = (1 << lg) - 1,
          inf = 1e9 + 10;
int n, from[maxm], to[maxm], W[maxm], cost[maxm];
vector<int> G[maxn];
char s[maxn];
struct Flow {
  int H[maxn], Q[M + 1], par[maxn], fl[maxn], s, t, n;
  bool mark[maxn];
  bool spfa() {
    for (int a = 0; a < n; a++) {
      H[a] = inf;
      fl[a] = 0;
    }
    H[s] = 0;
    int l = 0, r = 0;
    Q[r] = s;
    fl[s] = inf;
    r = (r + 1) & M;
    while (l != r) {
      int a = Q[l];
      l = (l + 1) & M;
      mark[a] = 0;
      for (int id : G[a]) {
        int b = to[id];
        if (H[a] + cost[id] < H[b] && W[id] > 0) {
          H[b] = H[a] + cost[id];
          par[b] = id;
          fl[b] = min(fl[a], W[id]);
          if (!mark[b]) {
            mark[b] = 1;
            Q[r] = b;
            r = (r + 1) & M;
          }
        }
      }
    }
    return fl[t] > 0;
  }
  int solve() {
    int val = 0;
    while (spfa()) {
      int b = t;
      while (b != s) {
        int id = par[b];
        val -= cost[id];
        W[id] -= fl[t];
        W[id ^ 1] += fl[t];
        b = from[id];
      }
    }
    return val;
  }
} flow;
int last = 0;
void add_edge(int a, int b, int c, int w) {
  from[last] = a;
  to[last] = b;
  cost[last] = +c;
  W[last] = w;
  G[a].push_back(last++);
  from[last] = b;
  to[last] = a;
  cost[last] = -c;
  W[last] = 0;
  G[b].push_back(last++);
}
int m;
char tmp[maxn];
int32_t main() {
  scanf("%d%s%d", &n, s, &m);
  flow.n = n + 3;
  flow.s = 0;
  flow.t = n + 2;
  for (int i = 0; i < m; i++) {
    int val;
    scanf("%s%d", tmp, &val);
    int sz = strlen(tmp);
    for (int j = 0; j < n - sz + 1; j++) {
      bool ok = 1;
      for (int k = 0; k < sz; k++) {
        if (s[j + k] != tmp[k]) {
          ok = 0;
          break;
        }
      }
      if (!ok) {
        continue;
      }
      add_edge(j + 1, j + sz + 1, -val, 1);
    }
  }
  int x;
  scanf("%d", &x);
  for (int i = 0; i < n + 2; i++) {
    add_edge(i, i + 1, 0, x);
  }
  printf("%d\n", flow.solve());
}
