#include <bits/stdc++.h>
using namespace std;
long f[203][203], s, t, c[203][203], sum, sta[20003], d[203], la[203], h, e;
char S[10003], in[203];
bool flow() {
  long i;
  h = 0;
  e = 1;
  sta[1] = 0;
  for (i = 1; i <= t; ++i) d[i] = 100000000;
  memset(in, 0, sizeof(in));
  in[t] = 1;
  while (h < e) {
    ++h;
    for (i = 1; i <= t; ++i)
      if (f[sta[h]][i])
        if (d[i] > d[sta[h]] + c[sta[h]][i]) {
          d[i] = d[sta[h]] + c[sta[h]][i];
          la[i] = sta[h];
          if (!in[i]) {
            sta[++e] = i;
            in[i] = 1;
          }
        }
    in[sta[h]] = 0;
  }
  return d[t] < 100000000;
}
void update() {
  long i, j, k;
  j = t;
  k = 100000000;
  do {
    k = min(f[la[j]][j], k);
    j = la[j];
  } while (j != 0);
  j = t;
  do {
    sum += c[la[j]][j] * k;
    f[la[j]][j] -= k;
    f[j][la[j]] += k;
    j = la[j];
  } while (j != 0);
  return;
}
int main() {
  std::ios::sync_with_stdio(false);
  long i, j, k, m, n;
  cin >> S;
  cin >> n;
  t = n + 27;
  for (i = 0; S[i] != '\0'; ++i) ++f[S[i] - 'a' + 1][t];
  for (i = 1; i <= n; ++i) {
    cin >> S >> m;
    f[s][i + 26] = m;
    for (j = 0; S[j] != '\0'; ++j) ++f[i + 26][S[j] - 'a' + 1];
    for (j = 1; j <= 26; ++j) {
      c[i + 26][j] = i;
      c[j][i + 26] = -i;
    }
  }
  while (flow()) update();
  for (i = 1; i <= 26; ++i)
    if (f[i][t] != 0) break;
  cout << (i <= 26 ? -1 : sum) << endl;
  return 0;
}
