#include <bits/stdc++.h>
using namespace std;
const int N = 105;
struct T {
  int from, to, val;
  int next, cost;
} edge[200001];
int len, re_flow;
int visit[200001], pre[200001], dist[200001], que[200001], vis[200001],
    pos[200001], map[100][100];
void init() {
  memset(vis, -1, sizeof(vis));
  len = 0;
}
void add(int from, int to, int val, int cost) {
  edge[len].from = from, edge[len].to = to, edge[len].val = val,
  edge[len].cost = cost;
  edge[len].next = vis[from], vis[from] = len++;
  edge[len].from = to, edge[len].to = from, edge[len].val = 0,
  edge[len].cost = -cost;
  edge[len].next = vis[to], vis[to] = len++;
}
int SPFA(int s, int t, int n) {
  int i, to, k;
  for (i = 0; i <= n; i++) {
    pre[i] = -1, visit[i] = 0;
  }
  int head, tail;
  head = tail = 0;
  for (i = 0; i <= n; i++) dist[i] = 0xffffff;
  que[tail++] = s, pre[s] = s, dist[s] = 0, visit[s] = 1;
  while (head != tail) {
    int from = que[head++];
    visit[from] = 0;
    for (k = vis[from]; k != -1; k = edge[k].next) {
      to = edge[k].to;
      if (edge[k].val > 0 && dist[from] + edge[k].cost < dist[to]) {
        dist[to] = dist[from] + edge[k].cost;
        pre[to] = from;
        pos[to] = k;
        if (!visit[to]) {
          visit[to] = 1;
          que[tail++] = to;
        }
      }
    }
  }
  if (pre[t] != -1 && dist[t] < 0xffffff) return 1;
  return 0;
}
int MinCostFlow(int s, int t, int n) {
  int flow = 0, cost = 0;
  while (SPFA(s, t, n)) {
    int from, min = 0xffffff;
    for (from = t; from != s; from = pre[from])
      min = min < edge[pos[from]].val ? min : edge[pos[from]].val;
    flow += min;
    cost += dist[t] * min;
    for (from = t; from != s; from = pre[from]) {
      edge[pos[from]].val -= min;
      edge[pos[from] ^ 1].val += min;
    }
  }
  if (flow != re_flow) return -1;
  return cost;
}
int input() {
  int n, st, ed, len, limit[N], cnt[30] = {0};
  char str_t[N], str[N][N];
  scanf("%s %d", str_t, &n);
  st = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s %d", str[i], &limit[i]);
    add(st, i, limit[i], 0);
    len = (int)strlen(str[i]);
    for (int j = 0; j < len; j++) {
      add(i, n + str[i][j] - 'a' + 1, 1, i);
    }
  }
  re_flow = len = (int)strlen(str_t);
  for (int i = 0; i < len; i++) {
    cnt[str_t[i] - 'a']++;
  }
  ed = n + 31;
  for (int i = 0; i < 30; i++) {
    if (cnt[i]) add(n + i + 1, ed, cnt[i], 0);
  }
  return ed;
}
int main() {
  init();
  int st = 0;
  int ed = input();
  printf("%d\n", MinCostFlow(st, ed, ed - st + 1));
  return 0;
}
