#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000000000000001;
const int N = 111;
char t[N];
char s[N][N];
int a[N];
int tl;
int flow[3 * N][3 * N], cap[3 * N][3 * N], n, m, vis[3 * N], poo, par[3 * N];
int dis[3 * N];
inline int wgt(int x, int y) {
  if (x == 1 && (y > 1 && y <= 1 + n))
    return y - 1;
  else if ((x > 1 && x <= 1 + n) && y == 1) {
    return -(x - 1);
  } else
    return 0;
}
int bfs(int s, int d) {
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  q.push(make_pair(0, s));
  int mn = (1 << 30), i, j;
  par[d] = -1;
  par[s] = -1;
  for (i = 1; i <= n; i++) {
    dis[i] = 999999;
  }
  dis[s] = 0;
  while (!q.empty()) {
    pair<int, int> hah = q.top();
    q.pop();
    int cur = hah.second;
    if (vis[cur] == poo) continue;
    vis[cur] = poo;
    if (cur == d) break;
    for (i = 1; i <= n; i++) {
      if (vis[i] != poo && cap[cur][i] - flow[cur][i] > 0 &&
          dis[i] > dis[cur] + wgt(cur, i)) {
        dis[i] = dis[cur] + wgt(cur, i);
        par[i] = cur;
        q.push(make_pair(dis[i], i));
      }
    }
  }
  if (par[d] == -1) return 0;
  int x = d;
  while (par[x] != -1) {
    int y = par[x];
    mn = min(mn, cap[y][x] - flow[y][x]);
    x = y;
  }
  x = d;
  while (par[x] != -1) {
    int y = par[x];
    flow[y][x] += mn;
    flow[x][y] -= mn;
    x = y;
  }
  return mn;
}
long long maxflow(int s, int d) {
  long long ret = 0, add = 0;
  ++poo;
  while ((add = bfs(s, d)) > 0) {
    ret += add;
    ++poo;
  }
  return ret;
}
int main() {
  scanf("%s", t);
  tl = strlen(t);
  int i, j;
  int n;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%s", s[i]);
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= n; i++) {
    cap[1][i + 1] = a[i];
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; s[i][j] != '\0'; j++) {
      cap[i + 1][s[i][j] - 'a' + 1 + 1 + n]++;
    }
  }
  for (i = 1; i <= tl; i++) {
    cap[t[i - 1] - 'a' + 1 + 1 + n][1 + n + 26 + i]++;
  }
  for (i = 1; i <= tl; i++) {
    cap[i + n + 26 + 1][1 + n + 26 + tl + 1] = 1;
  }
  ::n = n + 26 + tl + 2;
  long long ans = maxflow(1, n + 26 + tl + 2);
  cerr << "maxflow :" << ans << endl;
  ;
  if (ans != tl) {
    printf("-1\n");
    return 0;
  }
  ans = 0;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= 26; j++) {
      if (flow[i + 1][1 + n + j] > 0) {
        ans += 1LL * i * flow[i + 1][1 + n + j];
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
