#include <bits/stdc++.h>
using namespace std;
const int max_n = 1000;
const int mx = 100000000;
int n, t, len;
string st, s1;
int c[max_n][max_n], f[max_n][max_n], p[max_n][max_n], pr[max_n], dist[max_n],
    rel[max_n], kol[100];
void fb() {
  for (int i = 1; i <= t; i++) {
    rel[i] = -1;
    dist[i] = mx;
  }
  dist[1] = 0;
  rel[1] = 0;
  for (int it = 1; it <= t; it++) {
    for (int i = 1; i <= t; i++)
      if (rel[i] < it - 1)
        continue;
      else {
        for (int j = 1; j <= t; j++) {
          int g = c[i][j] - f[i][j];
          if (g > 0 && dist[i] + p[i][j] < dist[j]) {
            dist[j] = dist[i] + p[i][j];
            pr[j] = i;
            rel[j] = it;
          }
        }
      }
  }
}
int main() {
  cin >> st;
  len = st.size();
  for (int i = 0; i < len; i++) {
    c[1][st[i] - 'a' + 2]++;
  }
  cin >> n;
  t = 28 + 2 * n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> s1 >> x;
    int cur = s1.size();
    for (int j = 0; j <= 25; j++) kol[j] = 0;
    for (int j = 0; j < cur; j++) kol[s1[j] - 'a']++;
    c[27 + i][27 + i + n] = x;
    p[27 + i][27 + i + n] = i;
    p[27 + i + n][27 + i] = -i;
    for (int j = 0; j < 26; j++) c[j + 2][27 + i] = kol[j];
    c[27 + i + n][t] = mx;
  }
  while (true) {
    fb();
    if (dist[t] == mx)
      break;
    else {
      int x = t;
      int mn = mx;
      while (x != 1) {
        int y = pr[x];
        if (c[y][x] - f[y][x] < mn) mn = c[y][x] - f[y][x];
        x = y;
      }
      x = t;
      while (x != 1) {
        int y = pr[x];
        f[y][x] += mn;
        f[x][y] = -f[y][x];
        x = y;
      }
    }
  }
  int pt = 0;
  for (int i = 28 + n; i < t; i++) pt += f[i][t];
  if (pt < len) {
    cout << -1;
    return 0;
  }
  int cs = 0;
  for (int i = 1; i <= t; i++)
    for (int j = 1; j <= t; j++)
      if (f[i][j] > 0) cs += (f[i][j] * p[i][j]);
  cout << cs;
  return 0;
}
