#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int M = 30005;
const int inf = 99999999;
int n, m, tot, s, t, Cost, Flow;
int adj[M], nxt[M], flow[M], val[M], pre[M], data[M], dist[M], vis[M], d[M];
int g[N];
char pattern[N];
char text[N];
void ins(int x, int y, int f, int v) {
  adj[++tot] = y;
  nxt[tot] = g[x];
  g[x] = tot;
  flow[tot] = f;
  val[tot] = v;
  adj[++tot] = x;
  nxt[tot] = g[y];
  g[y] = tot;
  flow[tot] = 0;
  val[tot] = -v;
}
bool find() {
  int head = 0, tail = 1;
  d[1] = s;
  for (int i = 1; i <= t; i++) dist[i] = inf;
  dist[s] = 0;
  memset(vis, 0, sizeof(vis));
  vis[s] = 1;
  while (head != tail) {
    head = head % 3000 + 1;
    int now = d[head];
    for (int p = g[now]; p; p = nxt[p]) {
      if (flow[p] > 0 && dist[now] + val[p] < dist[adj[p]]) {
        dist[adj[p]] = dist[now] + val[p];
        pre[adj[p]] = p;
        if (!vis[adj[p]]) {
          tail = tail % 3000 + 1;
          d[tail] = adj[p];
          vis[adj[p]] = 1;
        }
      }
    }
    vis[now] = 0;
  }
  if (dist[t] != inf) {
    Cost += dist[t];
    return 1;
  }
  return 0;
}
void sap(int s, int t) {
  Cost = 0;
  Flow = 0;
  while (1) {
    if (find()) {
      Flow++;
      for (int u = t; u != s; u = adj[pre[u] ^ 1]) {
        flow[pre[u]]--;
        flow[pre[u] ^ 1]++;
      }
    } else
      break;
  }
}
int main() {
  memset(g, 0, sizeof(g));
  tot = 1;
  scanf("%s", text + 1);
  scanf("%d", &n);
  s = 26 + n + 1, t = s + 1;
  int cnt, len = strlen(text + 1);
  for (int j = 1; j <= 26; j++) {
    cnt = 0;
    for (int k = 1; k <= len; k++)
      if (text[k] == 'a' + j - 1) cnt++;
    ins(s, j, cnt, 0);
  }
  for (int i = 1; i <= n; i++) {
    int num;
    scanf("%s", pattern + 1);
    scanf("%d", &num);
    ins(26 + i, t, num, 0);
    len = strlen(pattern + 1);
    for (int j = 1; j <= 26; j++) {
      cnt = 0;
      for (int k = 1; k <= len; k++)
        if (pattern[k] == 'a' + j - 1) cnt++;
      ins(j, 26 + i, cnt, i);
    }
  }
  sap(s, t);
  if (Flow != strlen(text + 1))
    puts("-1");
  else
    printf("%d\n", Cost);
  return 0;
}
