#include <bits/stdc++.h>
using namespace std;
const int MAXV = 256;
const int MAXE = MAXV * 30;
const int INF = 0x3f3f3f3f;
struct SpfaCostFlow {
  int head[MAXV], ecnt;
  int to[MAXE], next[MAXE], flow[MAXE], cost[MAXE];
  int n, st, ed;
  void init(int n) {
    this->n = n;
    memset(head + 1, -1, n * sizeof(int));
    ecnt = 0;
  }
  void add_edge(int u, int v, int f, int c) {
    to[ecnt] = v;
    flow[ecnt] = f;
    cost[ecnt] = c;
    next[ecnt] = head[u];
    head[u] = ecnt++;
    to[ecnt] = u;
    flow[ecnt] = 0;
    cost[ecnt] = -c;
    next[ecnt] = head[v];
    head[v] = ecnt++;
  }
  int dis[MAXV], pre[MAXV];
  bool vis[MAXV];
  bool spfa() {
    memset(vis + 1, 0, n * sizeof(bool));
    memset(dis + 1, 0x3f, n * sizeof(int));
    queue<int> que;
    que.push(st);
    dis[st] = 0;
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      vis[u] = false;
      for (int p = head[u]; ~p; p = next[p]) {
        int v = to[p];
        if (flow[p] && dis[u] + cost[p] < dis[v]) {
          dis[v] = dis[u] + cost[p];
          pre[v] = p;
          if (!vis[v]) {
            que.push(v);
            vis[v] = true;
          }
        }
      }
    }
    return dis[ed] < INF;
  }
  int maxflow, mincost;
  int min_cost_flow(int ss, int tt) {
    st = ss, ed = tt;
    maxflow = mincost = 0;
    while (spfa()) {
      int u = ed, tmp = INF;
      while (u != st) {
        tmp = min(tmp, flow[pre[u]]);
        u = to[pre[u] ^ 1];
      }
      u = ed;
      while (u != st) {
        flow[pre[u]] -= tmp;
        flow[pre[u] ^ 1] += tmp;
        u = to[pre[u] ^ 1];
      }
      maxflow += tmp;
      mincost += tmp * dis[ed];
    }
    return mincost;
  }
} G;
char s[MAXV], a[MAXV];
int b, n;
int main() {
  scanf("%s", s);
  scanf("%d", &n);
  int ss = n + 1, tt = n + 2, len = strlen(s);
  G.init(tt + 26);
  for (int i = 0; i < 26; ++i)
    G.add_edge(ss, tt + i + 1, count(s, s + len, i + 'a'), 0);
  for (int i = 1; i <= n; ++i) {
    scanf("%s%d", a, &b);
    int l = strlen(a);
    for (int j = 0; j < 26; ++j)
      G.add_edge(tt + j + 1, i, count(a, a + l, j + 'a'), 0);
    G.add_edge(i, tt, b, i);
  }
  int ans = G.min_cost_flow(ss, tt);
  printf("%d\n", G.maxflow == len ? ans : -1);
}
