#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
struct edge {
  int u, v;
  int flow;
  int cost;
  edge() {}
  edge(int u, int v, int f, int c) : u(u), v(v), flow(f), cost(c) {}
};
struct MinCostMaxFlow {
  int N;
  vector<vector<int> > G;
  vector<edge> E;
  int numEdges;
  vector<int> found, dad;
  vector<int> dist;
  MinCostMaxFlow(int N) : N(N), G(N), found(N), dist(N), dad(N), numEdges(0) {}
  void addEdge(int from, int to, int capacity, int cost) {
    G[from].push_back(numEdges++);
    E.push_back(edge(from, to, capacity, cost));
    G[to].push_back(numEdges++);
    E.push_back(edge(to, from, 0, int(-1) * cost));
  }
  bool spfa(int s, int t) {
    fill(dad.begin(), dad.end(), -1);
    fill(dist.begin(), dist.end(), INF);
    fill(found.begin(), found.end(), 0);
    queue<int> Q;
    dist[s] = 0;
    Q.push(s);
    found[s] = true;
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      if (u == t) continue;
      for (int i = 0; i < G[u].size(); ++i) {
        edge &pres = E[G[u][i]];
        int v = pres.v;
        if (pres.flow <= 0) continue;
        if (dist[u] + pres.cost < dist[v]) {
          dad[v] = G[u][i];
          dist[v] = dist[u] + pres.cost;
          if (!found[v]) Q.push(v), found[v] = true;
        }
      }
      found[u] = false;
    }
    return (dad[t] != -1);
  }
  int dfs(int s, int t) {
    int flow = INF;
    for (int i = dad[t]; i != -1; i = dad[E[i].u]) {
      if (E[i].flow < flow) flow = E[i].flow;
    }
    for (int i = dad[t]; i != -1; i = dad[E[i].u]) {
      E[i].flow -= flow;
      E[i ^ 1].flow += flow;
    }
    return flow;
  }
  pair<int, int> getMaxFlow(int s, int t) {
    int totflow = 0;
    int totcost = 0;
    while (spfa(s, t)) {
      int amt = dfs(s, t);
      totflow += amt;
      totcost += dist[t] * (int)amt;
    }
    return make_pair(totflow, totcost);
  }
};
const int oo = (int)1e6;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int m;
  cin >> m;
  vector<string> str(m);
  vector<int> p(m);
  for (int i = 0; i < (m); ++i) {
    cin >> str[i] >> p[i];
  }
  int x;
  cin >> x;
  MinCostMaxFlow mcmf(n + 2);
  int source = n + 1;
  mcmf.addEdge(source, 0, x, 0);
  for (int i = 0; i < (n); ++i) {
    mcmf.addEdge(i, i + 1, x, 0);
  }
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j)
      if (i + ((int)str[j].size()) <= n) {
        bool ok = true;
        for (int k = 0; k < (((int)str[j].size())); ++k) {
          if (s[i + k] != str[j][k]) {
            ok = false;
            break;
          }
        }
        if (ok) {
          mcmf.addEdge(i, i + ((int)str[j].size()), 1, -p[j]);
        }
      }
  }
  pair<int, int> ans = mcmf.getMaxFlow(source, n);
  cout << -ans.second << "\n";
  return 0;
}
