#include <bits/stdc++.h>
using namespace std;
int F[155][155], C[155][155], dis[155];
int pre[155], T, inq[155];
bool spfa(int u) {
  int i, v, w;
  for (i = 0; i <= T; i++) dis[i] = 0x3fffffff, inq[i] = 0, pre[i] = -1;
  queue<int> q;
  q.push(u);
  dis[u] = 0;
  inq[u] = 1;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    inq[u] = 0;
    for (v = 0; v <= T; v++) {
      if (F[u][v] == 0) continue;
      if (dis[v] > dis[u] + C[u][v]) {
        dis[v] = dis[u] + C[u][v];
        pre[v] = u;
        if (!inq[v]) {
          q.push(v);
          inq[v] = 1;
        }
      }
    }
  }
  return dis[T] < 0x3fffffff;
}
int main() {
  char s[155];
  int i, j, c, ans, n, len;
  while (~scanf("%s", s)) {
    memset(F, 0, sizeof(F));
    memset(C, 0, sizeof(C));
    scanf("%d", &n);
    T = n + 28;
    len = strlen(s);
    for (i = 0; s[i]; i++) ++F[n + 2 + s[i] - 'a'][T];
    for (i = 1; i <= n; i++) {
      scanf("%s%d", s, &c);
      F[1][i + 1] = c;
      for (j = 0; s[j]; j++) {
        ++F[i + 1][n + 2 + s[j] - 'a'];
        C[i + 1][n + 2 + s[j] - 'a'] = i;
        C[n + 2 + s[j] - 'a'][i + 1] = -i;
      }
    }
    int flow = 0;
    ans = 0;
    while (spfa(1)) {
      int mins = 0x3fffffff;
      for (i = T; i != 1; i = pre[i]) mins = min(mins, F[pre[i]][i]);
      for (i = T; i != 1; i = pre[i]) {
        F[pre[i]][i] -= mins;
        F[i][pre[i]] += mins;
        ans += C[pre[i]][i] * mins;
      }
      flow += mins;
    }
    if (flow == len)
      printf("%d\n", ans);
    else
      puts("-1");
  }
  return 0;
}
