#include <bits/stdc++.h>
using namespace std;
vector<long long> v[205];
long long viz[205], fin, cap[205][205], fl[205][205], fr[205];
long long flux(long long nod, long long flmax) {
  viz[nod] = 1;
  if (nod == fin) {
    return flmax;
  }
  for (auto vec : v[nod]) {
    if (viz[vec] == 0 && cap[nod][vec] - fl[nod][vec] > 0) {
      long long tmp =
          min(flmax, flux(vec, min(cap[nod][vec] - fl[nod][vec], flmax)));
      if (tmp == 0) continue;
      flmax = tmp;
      fl[nod][vec] += flmax;
      fl[vec][nod] -= flmax;
      return flmax;
    }
  }
  return 0;
}
char s[205], st[205];
int main() {
  long long n, m, i, nec, capac, j, ans, fl;
  cin >> s;
  m = strlen(s);
  cin >> n;
  for (i = 0; i < m; i++) {
    fr[s[i] - 'a']++;
  }
  fin = n + 100;
  nec = m;
  for (i = 0; i < 26; i++) {
    v[i + n + 1].push_back(fin);
    cap[i + n + 1][fin] = fr[i];
  }
  for (i = 1; i <= n; i++) {
    cin >> st >> capac;
    memset(fr, 0, sizeof(fr));
    m = strlen(st);
    for (j = 0; j < m; j++) {
      fr[st[j] - 'a']++;
    }
    cap[0][i] = capac;
    v[0].push_back(i);
    for (j = 0; j < 26; j++) {
      v[i].push_back(j + n + 1);
      v[j + n + 1].push_back(i);
      cap[i][j + n + 1] = fr[j];
    }
  }
  ans = 0;
  for (i = 1; i <= n; i++) {
    memset(viz, 0, sizeof(viz));
    fl = flux(i, cap[0][i]);
    while (fl != 0) {
      nec -= fl;
      ans += fl * i;
      cap[0][i] -= fl;
      memset(viz, 0, sizeof(viz));
      fl = flux(i, cap[0][i]);
    }
  }
  if (nec != 0) {
    cout << -1 << '\n';
    return 0;
  }
  cout << ans << '\n';
}
