#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int M = 1e3 + 10;
class MaxFlowMinCost {
  typedef long long typef;
  typedef long long typec;
  static const int ME = 1e6 + 10;
  static const int MV = 1e3 + 10;
  queue<int> q;
  int n, cur[MV], pre[MV];
  bool used[MV], sign[MV];
  typef flow;
  typec cost, dist[MV];
  bool spfa(int s, int t) {
    for (int i = 0; i <= n; i++) {
      used[i] = sign[i] = dist[i] = 0;
    }
    used[s] = sign[s] = true;
    while (!q.empty()) q.pop();
    q.push(s);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      used[u] = false;
      for (int i = g.head[u]; ~i; i = g.e[i].next) {
        if (g.e[i].flow < 1) continue;
        int v = g.e[i].v;
        typec c = g.e[i].cost;
        if (!sign[v] || dist[v] > dist[u] + c) {
          dist[v] = dist[u] + c;
          sign[v] = true;
          pre[v] = u;
          cur[v] = i;
          if (used[v]) continue;
          used[v] = true;
          q.push(v);
        }
      }
    }
    return sign[t];
  }
  struct G {
    struct E {
      int v, next;
      typef flow;
      typec cost;
    } e[ME];
    int le, head[MV];
    void init(int n) {
      le = 0;
      for (int i = 0; i <= n; i++) head[i] = -1;
    }
    void add(int u, int v, typef flow, typec cost) {
      e[le].v = v;
      e[le].flow = flow;
      e[le].cost = cost;
      e[le].next = head[u];
      head[u] = le++;
    }
  } g;

 public:
  void init(int tn) {
    n = tn;
    g.init(n);
  }
  void add(int u, int v, typef flow, typec cost) {
    g.add(u, v, flow, cost);
    g.add(v, u, 0, -cost);
  }
  void solve(int s, int t) {
    flow = cost = 0;
    while (spfa(s, t)) {
      int temp = t;
      typef now = inf;
      while (temp != s) {
        now = min(now, g.e[cur[temp]].flow);
        temp = pre[temp];
      }
      flow += now;
      temp = t;
      while (temp != s) {
        int id = cur[temp];
        cost += now * g.e[id].cost;
        g.e[id].flow -= now;
        g.e[id ^ 1].flow += now;
        temp = pre[temp];
      }
    }
  }
  typef getflow() { return flow; }
  typec getcost() { return cost; }
} gx;
int n, m, x;
char a[M];
struct Word {
  char a[M];
  int p;
} word[M];
bool cmp(char c[], int s) {
  int len = strlen(c);
  for (int i = 0; i < len; i++) {
    if (c[i] != a[s + i]) return false;
  }
  return true;
}
long long solve() {
  int s = 0;
  int t = n + 1;
  gx.init(t);
  for (int i = 0; i <= n; i++) {
    gx.add(i, i + 1, x, 0);
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (!cmp(word[i].a, j)) continue;
      gx.add(j + 1, j + 1 + strlen(word[i].a), 1, -word[i].p);
    }
  }
  gx.solve(s, t);
  return -gx.getcost();
}
int main() {
  while (~scanf("%d%s", &n, a)) {
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      scanf("%s%d", word[i].a, &word[i].p);
    }
    scanf("%d", &x);
    printf("%I64d\n", solve());
  }
  return 0;
}
