#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const long long mod = 998244353;
struct edge {
  int u, v, cost, cap;
  edge() {}
  edge(int _u, int _v, int _c, int _cap) : u(_u), v(_v), cost(_c), cap(_cap) {}
  int get(int t) { return t ^ u ^ v; }
};
const int inf = 1e9;
template <class edge, int inf>
class edkarp {
 public:
  vector<edge> edges;
  vector<vector<int>> adj;
  int n;
  void init(int _n) {
    n = _n;
    adj.assign(n, vector<int>(0));
  }
  inline int comp(int i) { return i ^ 1; }
  inline int par(int i, int edge_num) { return edges[edge_num].get(i); }
  void add(int u, int v, int co, int capac) {
    adj[u].emplace_back(edges.size());
    edges.emplace_back(u, v, co, capac);
    adj[v].emplace_back(edges.size());
    edges.emplace_back(v, u, -co, 0);
  }
  void shortest_path(int v, vector<int> &d, vector<int> &p) {
    p.assign(n, -1);
    d.assign(n, inf);
    d[v] = 0;
    bool change = false;
    for (int i = 0; i < n - 1; i++) {
      change = false;
      for (int j = 0; j < edges.size(); j++) {
        if (d[edges[j].u] == inf || edges[j].cap == 0) continue;
        if (d[edges[j].v] > d[edges[j].u] + edges[j].cost) {
          d[edges[j].v] = d[edges[j].u] + edges[j].cost;
          p[edges[j].v] = j;
          change = true;
        }
      }
      if (!change) break;
    }
  }
  int mincost(int st, int tar, int k = inf) {
    vector<int> p, d;
    int flow = 0, cost = 0;
    int nf;
    while (flow < k) {
      shortest_path(st, d, p);
      if (d[tar] == inf) break;
      nf = k - flow;
      int cr = tar;
      while (cr != st) {
        nf = min(nf, edges[p[cr]].cap);
        cr = par(cr, p[cr]);
      }
      flow += nf;
      cost += nf * d[tar];
      cr = tar;
      while (cr != st) {
        edges[p[cr]].cap -= nf;
        edges[comp(p[cr])].cap += nf;
        cr = par(cr, p[cr]);
      }
    }
    return cost;
  }
};
void prefix_func(string &s, vector<int> &v) {
  int n = s.size();
  v.assign(n, 0);
  for (int i = 1; i < n; i++) {
    int j = v[i - 1];
    while (j >= 0 && s[j] != s[i]) {
      j = j == 0 ? -1 : v[j - 1];
    }
    v[i] = j + 1;
  }
}
int n, m, p[104], x, cr;
string s, w[104];
vector<int> v;
edkarp<edge, inf> fo;
void solve() {
  cin >> n >> s;
  cin >> m;
  fo.init(n + 2);
  fo.add(0, 1, 0, 100);
  for (int i = 1; i <= n; i++) {
    fo.add(i, i + 1, 0, 100);
  }
  for (int i = 0; i < m; i++) {
    cin >> w[i] >> p[i];
    prefix_func(w[i], v);
    cr = 0;
    for (int j = 0; j < n; j++) {
      while (cr >= 0 && s[j] != w[i][cr]) {
        cr = cr == 0 ? -1 : v[cr - 1];
      }
      cr++;
      if (cr == (int)w[i].size()) {
        cr = v[cr - 1];
        fo.add(j - (int)w[i].size() + 2, j + 2, -p[i], 1);
      }
    }
  }
  cin >> x;
  cout << -fo.mincost(0, n + 1, x) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
