#include <bits/stdc++.h>
using namespace std;
struct MinCostFlow {
  const int INF = 1000 * 1000 * 1000;
  const int MAX_CAP = 1000 * 1000 * 1000;
  struct edge {
    int from, v;
    int cap, flow;
    int cost, dist;
    int rev_index;
    bool residual() { return flow < cap; }
    edge(int _f, int _v, int _cap, int _cost)
        : from(_f), v(_v), cap(_cap), flow(0), cost(_cost), dist(_cost) {}
  };
  int n, s, t;
  vector<int> d;
  vector<edge*> p;
  vector<vector<edge>> g;
  vector<int> queued;
  MinCostFlow(int n) : n(n), d(n), p(n), g(n), queued(n) {}
  void bellman() {
    for (int i = 0; i < n; ++i) {
      d[i] = INF;
      queued[i] = 0;
    }
    queue<int> q;
    d[s] = 0;
    q.push(s);
    queued[s] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      queued[u] = 0;
      for (auto& i : g[u])
        if (i.residual() && d[i.v] > d[u] + i.dist) {
          d[i.v] = d[u] + i.dist;
          p[i.v] = &i;
          if (!queued[i.v]) {
            q.push(i.v);
            queued[i.v] = 1;
          }
        }
    }
  }
  pair<int, int> computeFlow(int s, int t) {
    this->s = s;
    this->t = t;
    int flow = 0;
    int cost = 0;
    while (true) {
      bellman();
      if (d[t] == INF) break;
      int c = 0;
      int f = MAX_CAP;
      for (int u = t; u != s; u = p[u]->from) {
        f = min(f, p[u]->cap - p[u]->flow);
      }
      for (int u = t; u != s; u = p[u]->from) {
        p[u]->flow += f;
        g[p[u]->v][p[u]->rev_index].flow -= f;
        c += p[u]->cost;
      }
      if (f * c >= 0) break;
      flow += f;
      cost += f * c;
    }
    return {flow, cost};
  }
  void addEdge(int a, int b, int f, int c) {
    assert(a != b);
    g[a].push_back(edge(a, b, f, c));
    g[b].push_back(edge(b, a, 0, -c));
    g[a].back().rev_index = int(g[b].size()) - 1;
    g[b].back().rev_index = int(g[a].size()) - 1;
  }
};
struct Test {
  string str;
  int n, m, x;
  vector<pair<string, int>> sub;
  Test(int n) : n(n) {
    cin >> str;
    cin >> m;
    sub.resize(m);
    for (auto& item : sub) {
      cin >> item.first >> item.second;
    }
    cin >> x;
  }
  void run() {
    int s = n + 1;
    int t = n;
    MinCostFlow flow(n + 2);
    for (int i = 0; i < n; ++i) {
      flow.addEdge(i, i + 1, x, 0);
    }
    flow.addEdge(s, 0, x, 0);
    for (int i = 0; i < n; ++i) {
      for (auto& j : sub) {
        int len = (int)j.first.size();
        if (str.substr(i, len) == j.first) {
          flow.addEdge(i, i + len, 1, -j.second);
        }
      }
    }
    cout << -flow.computeFlow(s, t).second << '\n';
  }
};
int main() {
  int n;
  cin >> n;
  Test a(n);
  a.run();
  return 0;
}
