#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
using namespace std;
struct Edge {
  int to, next, cap, flow, cost;
} edge[500000 + 10];
int head[500000 + 10], tol;
int pre[500000 + 10], dis[500000 + 10];
bool vis[500000 + 10];
int E;
int cost;
void init(int t) {
  E = t;
  tol = 0;
  memset(head, -1, sizeof head);
}
void addedge(int u, int v, int cap, int cost) {
  edge[tol].to = v;
  edge[tol].cap = cap;
  edge[tol].cost = cost;
  edge[tol].flow = 0;
  edge[tol].next = head[u];
  head[u] = tol++;
  edge[tol].to = u;
  edge[tol].cap = 0;
  edge[tol].cost = -cost;
  edge[tol].flow = 0;
  edge[tol].next = head[v];
  head[v] = tol++;
  if (tol >= 500000 + 10)
    while (1)
      ;
}
bool spfa(int s, int t) {
  queue<int> q;
  for (int i = 0; i < E; i++) {
    dis[i] = 1000000;
    vis[i] = false;
    pre[i] = -1;
  }
  dis[s] = 0;
  vis[s] = true;
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = false;
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].to;
      if (edge[i].cap > edge[i].flow && dis[v] > dis[u] + edge[i].cost) {
        dis[v] = dis[u] + edge[i].cost;
        pre[v] = i;
        if (!vis[v]) {
          vis[v] = true;
          q.push(v);
        }
      }
    }
  }
  if (pre[t] == -1)
    return false;
  else
    return true;
}
int minCostMaxflow(int s, int t, int &cost) {
  int flow = 0;
  cost = 0;
  while (spfa(s, t)) {
    int Min = 1000000;
    for (int i = pre[t]; i != -1; i = pre[edge[i ^ 1].to]) {
      if (Min > edge[i].cap - edge[i].flow) Min = edge[i].cap - edge[i].flow;
    }
    for (int i = pre[t]; i != -1; i = pre[edge[i ^ 1].to]) {
      edge[i].flow += Min;
      edge[i ^ 1].flow -= Min;
      cost += edge[i].cost * Min;
    }
    flow += Min;
  }
  return flow;
}
char str[700], str2[200];
int main() {
  int i, j, k, l, m, n, p, x;
  cin >> n;
  init(n + 5);
  scanf("%s", str + 1);
  int source = 0, sink = n + 1;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    scanf("%s%d", str2, &l);
    int f = strlen(str2);
    for (int j = 1; str[j]; j++) {
      for (k = 0, p = j; str2[k]; k++, p++) {
        if (str[p] == str2[k])
          ;
        else
          break;
      }
      if (k == f) {
        addedge(j, p, 1, -l);
      }
    }
  }
  scanf("%d", &x);
  for (int i = 1; i <= n + 1; i++) {
    addedge(i - 1, i, x, 0);
  }
  int cost = 0;
  minCostMaxflow(0, n + 1, cost);
  printf("%d\n", -cost);
}
