#include <bits/stdc++.h>
using std::max;
using std::min;
int n;
long long cap[400][400][2];
long long cst[400][400][2];
int par[400], pr[400];
long long p[400];
void bellman(int s, int t) {
  int i, j, k, h;
  for (i = 0; i <= n; i++) {
    p[i] = 10000000000000000LL;
    pr[i] = -1;
  }
  p[s] = 0;
  for (h = 0; h <= n; h++)
    for (i = 0; i <= n; i++)
      for (j = 0; j <= n; j++)
        for (k = 0; k <= 1; k++) {
          if (cap[i][j][k] <= 0) continue;
          if (p[j] > p[i] + cst[i][j][k]) p[j] = p[i] + cst[i][j][k];
        }
}
bool dijkstra(int s, int t) {
  int v, i, k;
  bool intree[400];
  long long dst[400], men, c;
  for (i = 0; i <= n; i++) {
    dst[i] = 10000000000000000LL;
    par[i] = -1;
    pr[i] = -1;
    intree[i] = false;
  }
  dst[s] = 0;
  v = s;
  while (!intree[v]) {
    intree[v] = true;
    for (i = 0; i <= n; i++) {
      if (intree[i]) continue;
      for (k = 0; k <= 1; k++) {
        if (cap[v][i][k] <= 0) continue;
        c = cst[v][i][k] + p[v] - p[i];
        if (dst[i] > dst[v] + c) {
          dst[i] = dst[v] + c;
          par[i] = v;
          pr[i] = k;
        }
      }
    }
    men = 10000000000000000LL;
    for (i = 0; i <= n; i++) {
      if (intree[i]) continue;
      if (dst[i] < men) {
        men = dst[i];
        v = i;
      }
    }
  }
  for (i = 0; i <= n; i++) p[i] += dst[i];
  return intree[t];
}
long long mincost(int s, int t) {
  int i, j, k, v;
  long long aug, ret = 0;
  bellman(s, t);
  while (dijkstra(s, t)) {
    v = t;
    aug = 10000000000000000LL;
    while (v != s) {
      if (aug > cap[par[v]][v][pr[v]]) aug = cap[par[v]][v][pr[v]];
      v = par[v];
    }
    v = t;
    while (v != s) {
      cap[par[v]][v][pr[v]] -= aug;
      cap[v][par[v]][1 - pr[v]] += aug;
      v = par[v];
    }
  }
  for (i = 0; i <= n; i++)
    for (j = 0; j <= n; j++) ret += cap[j][i][1] * cst[i][j][0];
  return ret;
}
void initFlowNet(int nn) {
  n = nn;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cst[i][j][1] = -cst[j][i][0];
      cap[i][j][1] = 0;
    }
  }
}
char t[200];
char s[200];
int main() {
  scanf("%s", t);
  int nstrings;
  scanf("%d", &nstrings);
  memset(cap, 0, sizeof(cap));
  int source = 0;
  int sink = 1;
  int n = 28;
  for (int i = 0; i < 26; i++) {
    cap[source][i + 2][0] = 0;
    cst[source][i + 2][0] = 0;
  }
  for (int i = 0; t[i]; i++) {
    int id = 2 + t[i] - 'a';
    cap[source][id][0]++;
  }
  for (int i = 0; i < nstrings; i++) {
    int a;
    scanf(" %s %d", s, &a);
    for (int j = 0; s[j]; j++) {
      int id = 2 + s[j] - 'a';
      cap[id][n][0]++;
      cst[id][n][0] = i + 1;
    }
    cap[n][sink][0] = a;
    cst[n][sink][0] = 0;
    n++;
  }
  initFlowNet(n);
  long long cost = mincost(source, sink);
  bool possible = true;
  for (int i = 0; i < 26; i++) {
    if (cap[source][i + 2][0] != 0) {
      possible = false;
      break;
    }
  }
  if (!possible)
    printf("-1\n");
  else
    printf("%I64d\n", cost);
}
