#include <bits/stdc++.h>
using namespace std;
int cap[200][200];
int cost[200][200];
int fnet[200][200], adj[200][200], deg[200];
int par[200], d[200], q[200], inq[200], qs;
int pi[200];
bool dijkstra(int n, int s, int t) {
  memset(d, 0x3F, sizeof(d));
  memset(par, -1, sizeof(par));
  memset(inq, -1, sizeof(inq));
  d[s] = qs = 0;
  inq[q[qs++] = s] = 0;
  par[s] = n;
  while (qs) {
    int u = q[0];
    inq[u] = -1;
    q[0] = q[--qs];
    if (qs) inq[q[0]] = 0;
    for (int i = 0, j = 2 * i + 1, t; j < qs; i = j, j = 2 * i + 1) {
      if (j + 1 < qs && d[q[j + 1]] < d[q[j]]) j++;
      if (d[q[j]] >= d[q[i]]) break;
      {
        t = q[i];
        q[i] = q[j];
        q[j] = t;
        t = inq[q[i]];
        inq[q[i]] = inq[q[j]];
        inq[q[j]] = t;
      };
    }
    for (int k = 0, v = adj[u][k]; k < deg[u]; v = adj[u][++k]) {
      if (fnet[v][u] && d[v] > (d[u] + pi[u] - pi[v]) - cost[v][u])
        d[v] = (d[u] + pi[u] - pi[v]) - cost[v][par[v] = u];
      if (fnet[u][v] < cap[u][v] && d[v] > (d[u] + pi[u] - pi[v]) + cost[u][v])
        d[v] = (d[u] + pi[u] - pi[v]) + cost[par[v] = u][v];
      if (par[v] == u) {
        if (inq[v] < 0) {
          inq[q[qs] = v] = qs;
          qs++;
        }
        for (int i = inq[v], j = (i - 1) / 2, t; d[q[i]] < d[q[j]];
             i = j, j = (i - 1) / 2) {
          t = q[i];
          q[i] = q[j];
          q[j] = t;
          t = inq[q[i]];
          inq[q[i]] = inq[q[j]];
          inq[q[j]] = t;
        };
      }
    }
  }
  for (int i = 0; i < n; i++)
    if (pi[i] < (INT_MAX / 2)) pi[i] += d[i];
  return par[t] >= 0;
}
int mcmf4(int n, int s, int t, int &fcost) {
  memset(deg, 0, sizeof(deg));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (cap[i][j] || cap[j][i]) adj[i][deg[i]++] = j;
  memset(fnet, 0, sizeof(fnet));
  memset(pi, 0, sizeof(pi));
  int flow = fcost = 0;
  while (dijkstra(n, s, t)) {
    int bot = INT_MAX;
    for (int v = t, u = par[v]; v != s; u = par[v = u])
      bot = min(bot, fnet[v][u] ? fnet[v][u] : (cap[u][v] - fnet[u][v]));
    for (int v = t, u = par[v]; v != s; u = par[v = u])
      if (fnet[v][u]) {
        fnet[v][u] -= bot;
        fcost -= bot * cost[v][u];
      } else {
        fnet[u][v] += bot;
        fcost += bot * cost[u][v];
      }
    flow += bot;
  }
  return flow;
}
int main() {
  int n, i, v, so, ta, j;
  string t;
  while (cin >> t) {
    cin >> n;
    string s[n + 1];
    int a[n + 1];
    int alpha[n + 1][26], al[26];
    for (i = 0; i <= n; i++)
      for (j = 0; j < 26; j++) alpha[i][j] = 0;
    for (i = 0; i < 26; i++) al[i] = 0;
    memset(cap, 0, sizeof cap);
    for (i = 1; i <= n; i++) {
      cin >> s[i];
      cin >> a[i];
    }
    for (i = 1; i <= n; i++) {
      for (j = 0; j < s[i].size(); j++) alpha[i][s[i][j] - 'a']++;
    }
    for (i = 0; i < t.size(); i++) al[t[i] - 'a']++;
    v = n + 28;
    so = 0;
    ta = n + 27;
    for (i = 1; i <= n; i++) {
      cap[0][i] = a[i];
      cost[0][i] = i;
    }
    for (i = 1; i <= n; i++) {
      for (j = 0; j < 26; j++) {
        cap[i][n + j + 1] = alpha[i][j];
        cost[i][n + j + 1] = 0;
      }
    }
    for (i = n + 1; i <= n + 26; i++) {
      cap[i][n + 27] = al[i - n - 1];
      cost[i][n + 27] = 0;
    }
    int fcost;
    int flow = mcmf4(v, so, ta, fcost);
    if (flow < t.size())
      cout << "-1\n";
    else
      cout << fcost << "\n";
  }
  return 0;
}
