#include <bits/stdc++.h>
using namespace std;
const int maxv = 100000 + 10;
const int maxe = 1000000 + 10;
const int inf = 0x3f3f3f3f;
struct node {
  int v, w, c, next;
} edge[maxe];
int head[maxv], pre[maxv], d[maxv], num[30];
bool vis[maxv];
int cnt, mx, ans, s, t, n, m;
char str[100 + 10];
void addedge(int v, int u, int c, int w) {
  edge[cnt].v = u;
  edge[cnt].c = c;
  edge[cnt].w = w;
  edge[cnt].next = head[v];
  head[v] = cnt++;
  edge[cnt].v = v;
  edge[cnt].c = 0;
  edge[cnt].w = -w;
  edge[cnt].next = head[u];
  head[u] = cnt++;
}
bool spfa() {
  memset(d, 0x3f, sizeof(d));
  memset(vis, 0, sizeof(vis));
  int maxt = d[0];
  d[s] = 0;
  pre[s] = -1;
  vis[s] = 1;
  queue<int> Q;
  Q.push(s);
  while (!Q.empty()) {
    int now = Q.front();
    Q.pop();
    vis[now] = 0;
    for (int i = head[now]; ~i; i = edge[i].next) {
      int k = edge[i].v;
      if (edge[i].c && d[now] + edge[i].w < d[k]) {
        d[k] = d[now] + edge[i].w;
        pre[k] = i;
        if (!vis[k]) {
          vis[k] = 1;
          Q.push(k);
        }
      }
    }
  }
  return d[t] < maxt;
}
void dfs() {
  int flow = inf;
  for (int i = t; i != s; i = edge[pre[i] ^ 1].v)
    flow = min(flow, edge[pre[i]].c);
  for (int i = t; i != s; i = edge[pre[i] ^ 1].v) {
    edge[pre[i]].c -= flow;
    edge[pre[i] ^ 1].c += flow;
  }
  mx += flow;
  ans += flow * d[t];
}
int id(char ch) { return ch - 'a'; }
int main() {
  memset(head, -1, sizeof(head));
  cnt = 0;
  scanf("%s%d", str, &n);
  s = 26 + n + 1;
  t = 26 + n + 2;
  int len = strlen(str);
  for (int i = 0; i < len; i++) num[id(str[i])]++;
  for (int i = 0; i < 26; i++)
    if (num[i]) addedge(s, i, num[i], 0);
  for (int i = 0; i < n; i++) {
    scanf("%s%d", str, &m);
    int l = strlen(str);
    memset(num, 0, sizeof(num));
    for (int j = 0; j < l; j++) num[id(str[j])]++;
    for (int j = 0; j < 26; j++)
      if (num[j]) {
        addedge(j, i + 26, num[j], i + 1);
      }
    addedge(i + 26, t, m, 0);
  }
  while (spfa()) dfs();
  if (mx != len)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
