#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 26 + 1 + 1 + 1;
int d[N], inq[N], par[N], S, T, n, f[N][N], a[N][N], x[N][N];
bool fb() {
  queue<int> q;
  int u, v, tg;
  for (int i = 1; i <= T; ++i) d[i] = 1e9, par[i] = 0, inq[i] = 0;
  q.push(S);
  d[S] = 0;
  inq[S] = 1;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    inq[u] = 0;
    for (v = 1; v <= T; ++v) {
      if (v != u) {
        if (x[u][v] > f[u][v]) {
          tg = 0;
          if (f[u][v] >= 0)
            tg = a[u][v];
          else
            tg = 0 - a[u][v];
          if (d[v] > d[u] + tg) {
            d[v] = d[u] + tg;
            par[v] = u;
            if (!inq[v]) {
              q.push(v);
              inq[v] = 1;
            }
          }
        }
      }
    }
  }
  if (d[T] < 1e9) return 1;
  return 0;
}
int ans = 0;
int cnt[30];
int sol(int delta) {
  int v;
  v = T;
  while (v != S) {
    if (f[par[v]][v] < 0)
      delta = min(delta, 0 - f[par[v]][v]);
    else
      delta = min(delta, x[par[v]][v] - f[par[v]][v]);
    v = par[v];
  }
  v = T;
  while (v != S) {
    f[par[v]][v] += delta;
    f[v][par[v]] -= delta;
    v = par[v];
  }
  ans += delta * d[T];
  return delta;
}
string s[N], t;
int val[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i] >> val[i];
  }
  for (char c : t) {
    ++cnt[c - 'a' + 1];
  }
  S = 26 + n + 1;
  T = 26 + n + 2;
  for (int i = 1; i <= 26; ++i) x[S][i] = cnt[i];
  for (int i = 1; i <= n; ++i) {
    memset(cnt, 0, sizeof(cnt));
    for (char c : s[i]) {
      ++cnt[c - 'a' + 1];
    }
    for (int c = 1; c <= 26; ++c) {
      x[c][i + 26] = cnt[c];
      a[c][i + 26] = a[i + 26][c] = i;
    }
    x[i + 26][T] = val[i];
  }
  int sz = t.size();
  while (fb()) {
    sz -= sol(sz);
    if (sz <= 0) break;
  }
  if (sz > 0)
    cout << -1;
  else
    cout << ans;
  return 0;
}
