#include <bits/stdc++.h>
using namespace std;
long long int powmod(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int x = powmod(a, b / 2);
  long long int y = (x * x) % 1000000007;
  if (b % 2) return (a * y) % 1000000007;
  return y % 1000000007;
}
struct edge {
  int x, y;
  int cap, cost;
};
queue<int> q;
class MCMF {
 public:
  vector<edge> E;
  vector<int> adj[510];
  int n, prev1[510], mark[510];
  int dist[510];
  MCMF(int k) { n = k; }
  void addEdge(int x, int y, int cap, int cost) {
    edge e1 = {x, y, cap, cost};
    edge e2 = {y, x, 0, -cost};
    adj[x].push_back(E.size());
    E.push_back(e1);
    adj[y].push_back(E.size());
    E.push_back(e2);
  }
  int dfs(int s, int t) {
    int z = 1e9;
    for (int i = t; i != s; i = E[prev1[i]].x) z = min(z, E[prev1[i]].cap);
    for (int i = t; i != s; i = E[prev1[i]].x) {
      E[prev1[i]].cap -= z;
      E[prev1[i] ^ 1].cap += z;
    }
    return z;
  }
  bool spfa(int s, int t) {
    q.empty();
    int i;
    for (i = 0; i <= n; i++) {
      mark[i] = 0;
      prev1[i] = -1;
      dist[i] = 1e9;
    }
    q.push(s);
    dist[s] = 0;
    mark[s] = 1;
    while (!q.empty()) {
      int t1 = q.front();
      q.pop();
      mark[t1] = 0;
      for (auto ind : adj[t1]) {
        edge e = E[ind];
        if (e.cap <= 0) continue;
        if (dist[e.y] > (dist[t1] + e.cost)) {
          dist[e.y] = dist[t1] + e.cost;
          prev1[e.y] = ind;
          if (!mark[e.y]) {
            mark[e.y] = 1;
            q.push(e.y);
          }
        }
      }
    }
    return (prev1[t] != -1);
  }
  pair<int, int> minCostMaxFlow(int s, int t) {
    int flowcost = 0;
    int flow = 0;
    while (spfa(s, t)) {
      int val = dfs(s, t);
      flow += val;
      flowcost += val * dist[t];
    }
    return make_pair(flow, flowcost);
  }
};
int main() {
  int n;
  scanf("%d", &n);
  MCMF mcmf(n + 2);
  int source = 0, sink = n + 1;
  char s[510];
  scanf("%s", s);
  int m;
  scanf("%d", &m);
  while (m--) {
    char t[510];
    scanf("%s", t);
    int w;
    scanf("%d", &w);
    int l = strlen(t);
    for (int i = 0; i < n; i++) {
      bool f = false;
      for (int j = 0; j < l; j++)
        if (t[j] != s[i + j]) f = true;
      if (!f) mcmf.addEdge(i + 1, i + l + 1, 1, -w);
    }
  }
  int x;
  scanf("%d", &x);
  mcmf.addEdge(source, 1, x, 0);
  mcmf.addEdge(n, sink, x, 0);
  for (int i = 1; i < n; i++) mcmf.addEdge(i, i + 1, x, 0);
  pair<int, int> ans = mcmf.minCostMaxFlow(source, sink);
  ans.second *= -1;
  printf("%d\n", ans.second);
  return 0;
}
