#include <bits/stdc++.h>
using namespace std;
const int N = 200;
const int MAXE = 40000;
const int inf = 1 << 30;
int head[N], s, t, cnt, n, m, ans;
int d[N], pre[N];
bool vis[N];
int q[MAXE];
int llll;
struct Edge {
  int u, v, c, w, next;
} edge[MAXE];
void addedge(int u, int v, int w, int c) {
  edge[cnt].u = u;
  edge[cnt].v = v;
  edge[cnt].w = w;
  edge[cnt].c = c;
  edge[cnt].next = head[u];
  head[u] = cnt++;
  edge[cnt].v = u;
  edge[cnt].u = v;
  edge[cnt].w = -w;
  edge[cnt].c = 0;
  edge[cnt].next = head[v];
  head[v] = cnt++;
}
int SPFA() {
  int l, r;
  memset(pre, -1, sizeof(pre));
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i <= t; i++) d[i] = inf;
  d[s] = 0;
  l = 0;
  r = 0;
  q[r++] = s;
  vis[s] = 1;
  while (l < r) {
    int u = q[l++];
    vis[u] = 0;
    for (int j = head[u]; j != -1; j = edge[j].next) {
      int v = edge[j].v;
      if (edge[j].c > 0 && d[u] + edge[j].w < d[v]) {
        d[v] = d[u] + edge[j].w;
        pre[v] = j;
        if (!vis[v]) {
          vis[v] = 1;
          q[r++] = v;
        }
      }
    }
  }
  if (d[t] == inf) return 0;
  return 1;
}
void MCMF() {
  int flow = 0;
  while (SPFA()) {
    int u = t;
    int mini = inf;
    while (u != s) {
      if (edge[pre[u]].c < mini) mini = edge[pre[u]].c;
      u = edge[pre[u]].u;
    }
    flow += mini;
    ans += d[t] * mini;
    u = t;
    while (u != s) {
      edge[pre[u]].c -= mini;
      edge[pre[u] ^ 1].c += mini;
      u = edge[pre[u]].u;
    }
  }
  if (flow != llll)
    printf("-1\n");
  else
    printf("%d\n", ans);
}
string zz, tt[N];
int ss[N];
int summm[50];
int main() {
  cin >> zz;
  llll = zz.size();
  cin >> n;
  cnt = 0;
  memset(head, -1, sizeof(head));
  for (int i = 1; i <= n; i++) {
    cin >> tt[i] >> ss[i];
  }
  s = 0;
  t = 27 + n;
  for (int i = 1; i <= n; i++) addedge(i + 26, t, 0, ss[i]);
  for (int i = 0; i < 26; i++) {
    int sum = 0;
    for (int j = 0; j < zz.size(); j++)
      if (zz[j] - 'a' == i) sum++;
    addedge(s, i + 1, 0, sum);
  }
  for (int i = 1; i <= n; i++)
    for (int k = 0; k < 26; k++) {
      int sum = 0;
      for (int j = 0; j < tt[i].size(); j++)
        if (tt[i][j] - 'a' == k) sum++;
      addedge(k + 1, i + 26, i, sum);
    }
  MCMF();
  return 0;
}
