#include <bits/stdc++.h>
using namespace std;
template <class T>
bool remin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool remax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int nxt() {
  int first;
  scanf("%d", &first);
  return first;
}
long long gcd(long long a, long long b) {
  a = abs(a);
  b = abs(b);
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
struct pt {
  long long first, second;
  pt() {}
  pt(long long first, long long second) : first(first), second(second) {}
  inline pt operator-(const pt &r) const {
    return pt(first - r.first, second - r.second);
  }
  inline pt operator+(const pt &r) const {
    return pt(first + r.first, second + r.second);
  }
  inline pt operator*(const long double &r) const {
    return pt(first * r, second * r);
  }
  inline long long sqlen() const {
    return abs(first * first + second * second);
  }
  inline bool operator<(const pt &r) const {
    if (first != r.first) return first < r.first;
    return second < r.second;
  }
  inline bool operator==(const pt &r) const {
    return first == r.first && second == r.second;
  }
};
ostream &operator<<(ostream &os, const pt &p) {
  return os << "(" << p.first << "," << p.second << ")";
}
inline long long cross(const pt &l, const pt &r) {
  return l.first * r.second - l.second * r.first;
}
inline long long dot(const pt &l, const pt &r) {
  return l.first * r.first + l.second * r.second;
}
long long pwmod(long long a, long long n, long long mod) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}
template <typename T>
inline T sqr(T first) {
  return first * first;
}
const long long INF = LLONG_MAX;
struct Edge {
  int fr, to;
  long long c, cost, f;
  Edge() {}
  Edge(int fr, int to, long long c, long long cost)
      : fr(fr), to(to), c(c), cost(cost), f(0) {}
};
const int N = 510;
struct G {
  vector<Edge> e;
  vector<int> g[N];
  char u[N];
  long long d[N];
  int q[N];
  int p[N];
  int n, s, t;
  void addEdge(int fr, int to, long long c, long long cost) {
    g[fr].push_back(int(e.size()));
    e.push_back(Edge(fr, to, c, cost));
    g[to].push_back(int(e.size()));
    e.push_back(Edge(to, fr, 0, -cost));
  }
  bool fb() {
    memset(p, -1, n * sizeof(int));
    memset(d, 0x3f, n * sizeof(long long));
    memset(u, 0, n * sizeof(char));
    d[s] = 0;
    u[s] = 1;
    int q1 = 0, q2 = 0;
    q[q2++] = s;
    while (q1 != q2) {
      int v = q[q1++];
      if (q1 == N) q1 = 0;
      u[v] = 0;
      for (int id : g[v]) {
        if (e[id].f == e[id].c) continue;
        int to = e[id].to;
        long long len = e[id].cost;
        if (d[to] > d[v] + len) {
          d[to] = d[v] + len;
          p[to] = id;
          if (!u[to]) {
            q[q2++] = to;
            if (q2 == N) q2 = 0;
            u[to] = 1;
          }
        }
      }
    }
    return p[t] != -1;
  }
  long long push(long long pushed = INF) {
    int v = t;
    while (v != s) {
      pushed = min(pushed, e[p[v]].c - e[p[v]].f);
      v = e[p[v]].fr;
    }
    v = t;
    while (v != s) {
      e[p[v]].f += pushed;
      e[p[v] ^ 1].f -= pushed;
      v = e[p[v]].fr;
    }
    return pushed;
  }
  pair<long long, long long> minCostFlow(int S, int T, long long need) {
    s = S, t = T;
    long long flow = 0;
    long long cost = 0;
    while (fb() && need > 0) {
      long long add = push(need);
      cost += add * d[t];
      flow += add;
    }
    return make_pair(flow, cost);
  }
};
char buf[10000];
inline void solve() {
  int n = nxt();
  scanf("%s", buf);
  string s = buf;
  int m = nxt();
  vector<pair<string, int> > a(m);
  for (int i = 0; i < (int)(m); i++) {
    scanf("%s", buf);
    string t = buf;
    int c = nxt();
    a[i].first = t;
    a[i].second = c;
  }
  int first = nxt();
  G g;
  g.n = n + 2;
  for (int i = 0; i < (int)(n + 1); i++) {
    g.addEdge(i, i + 1, first, 0);
  }
  for (int i = 0; i < (int)(m); i++) {
    for (int j = 0; j < (int)(max(0, int(n - a[i].first.length() + 1))); j++) {
      if (s.substr(j, a[i].first.length()) == a[i].first) {
        g.addEdge(j + 1, j + a[i].first.length() + 1, 1, -a[i].second);
      }
    }
  }
  auto res = g.minCostFlow(0, n + 1, first);
  cout << -res.second << "\n";
}
void prepare() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  prepare();
  int t = 1;
  for (int i = 0; i < (int)(t); i++) {
    solve();
  }
  return 0;
}
