#include <bits/stdc++.h>
using namespace std;
int n, src, dest;
char t[150], s[150];
bool vis[150];
int pre[150];
int num[26] = {0};
int d[150], head[150], cnt = 0;
struct Edge {
  int u, v, flow, cost, next;
} e[150 * 150];
int sumFlow, minCost;
bool spfa() {
  queue<int> q;
  memset(vis, 0, sizeof(vis));
  memset(pre, -1, sizeof(pre));
  for (int i = 0; i <= dest; i++) d[i] = 1 << 20;
  d[src] = 0;
  q.push(src);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = head[u]; i != -1; i = e[i].next) {
      int v = e[i].v;
      if (e[i].flow > 0 && d[v] > d[u] + e[i].cost) {
        d[v] = d[u] + e[i].cost;
        pre[v] = i;
        if (!vis[v]) q.push(v), vis[v] = 1;
      }
    }
  }
  return d[dest] != 1 << 20;
}
void work() {
  sumFlow = minCost = 0;
  while (spfa()) {
    int flow = 1 << 20;
    for (int i = pre[dest]; i != -1; i = pre[e[i].u]) {
      flow = min(flow, e[i].flow);
    }
    sumFlow += flow;
    for (int i = pre[dest]; i != -1; i = pre[e[i].u]) {
      e[i].flow -= flow;
      e[i ^ 1].flow += flow;
    }
    minCost += flow * d[dest];
  }
}
void add(int u, int v, int flow, int cost) {
  e[cnt].u = u;
  e[cnt].v = v;
  e[cnt].flow = flow;
  e[cnt].cost = cost;
  e[cnt].next = head[u];
  head[u] = cnt++;
  e[cnt].u = v;
  e[cnt].v = u;
  e[cnt].flow = 0;
  e[cnt].cost = -cost;
  e[cnt].next = head[v];
  head[v] = cnt++;
}
void show() {
  for (int i = 0; i < 25; i++) printf("%d ", num[i]);
  printf("%d\n", num[25]);
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%s", t);
  int len = strlen(t);
  for (int i = 0; i < len; i++) num[t[i] - 'a']++;
  for (int i = 1; i <= 26; i++) {
    if (num[i - 1]) {
      add(0, i, num[i - 1], 0);
    }
  }
  scanf("%d", &n);
  src = 0, dest = 26 + n + 1;
  for (int i = 1; i <= n; i++) {
    int w;
    scanf("%s %d", s, &w);
    add(i + 26, dest, w, 0);
    memset(num, 0, sizeof(num));
    for (int j = 0; s[j]; j++) num[s[j] - 'a']++;
    for (int j = 1; j <= 26; j++) {
      if (num[j - 1]) {
        add(j, i + 26, num[j - 1], i);
      }
    }
  }
  work();
  if (sumFlow == len) {
    printf("%d\n", minCost);
  } else {
    puts("-1");
  }
  return 0;
}
