#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
template <class T, class U>
inline void Max(T &a, U b) {
  if (a < b) a = b;
}
template <class T, class U>
inline void Min(T &a, U b) {
  if (a > b) a = b;
}
inline void add(int &a, int b) {
  a += b;
  while (a >= 1000000007) a -= 1000000007;
}
int pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = ans * (long long)a % 1000000007;
    a = (long long)a * a % 1000000007;
    b >>= 1;
  }
  return ans;
}
char b[505];
const int M = 1000000;
int q[505], h[505], cnt, head[600], d[600], p[600], vis[600];
int cal(int i, int j) {
  return (h[j] - 1LL * h[i] * q[j - i] % 1000000007 + 1000000007) % 1000000007;
}
struct node {
  int v, c, w, _next;
} g[200010];
void add(int a, int b, int c, int w) {
  g[cnt] = {b, c, w, head[a]};
  head[a] = cnt++;
  g[cnt] = {a, 0, -w, head[b]};
  head[b] = cnt++;
}
bool bfs(int s, int t) {
  for (int i = 0; i < t + 1; i++) d[i] = -1000000007, vis[i] = 0;
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = head[u]; ~i; i = g[i]._next) {
      int j = g[i].v, k = g[i].w;
      if (g[i].c && d[j] < d[u] + k) {
        d[j] = d[u] + k;
        p[j] = i;
        if (!vis[j]) vis[j] = 1, q.push(j);
      }
    }
  }
  return d[t] > -1000000007;
}
int max_flow(int s, int t) {
  int ans = 0;
  while (bfs(s, t)) {
    int first = t, f = 1000000007;
    while (first != s) {
      Min(f, g[p[first]].c), first = g[p[first] ^ 1].v;
    }
    ans += d[t] * f;
    first = t;
    while (first != s) {
      g[p[first]].c -= f, g[p[first] ^ 1].c += f, first = g[p[first] ^ 1].v;
    }
  }
  return ans;
}
int main() {
  int i, j, k = 0, ca = 0, T, K, m = 0, n;
  scanf("%d%s%d", &n, b, &m);
  q[0] = 1;
  for (int i = 0; i < n; i++)
    h[i + 1] = (h[i] * 29LL + b[i]) % 1000000007,
          q[i + 1] = q[i] * 29LL % 1000000007;
  memset(head, -1, sizeof(head));
  int s = 0, t = n + 1;
  for (int i = 0; i < m; i++) {
    scanf("%s%d", b, &k);
    int len = strlen(b);
    long long st = 0;
    for (int j = 0; j < len; j++) st = (st * 29LL + b[j]) % 1000000007;
    for (int j = 0; j < n - len + 1; j++) {
      if (cal(j, j + len) == st) add(j + 1, j + len + 1, 1, k);
    }
  }
  scanf("%d", &k);
  for (int i = 0; i < n + 1; i++) add(i, i + 1, k, 0);
  int ans = max_flow(s, t);
  printf("%d\n", ans);
  return 0;
}
