#include <bits/stdc++.h>
using namespace std;
const int maxn = 300, maxm = 30 * maxn, geps = 1, inf = 0x3fffffff;
const int maxV = maxn + geps, maxE = maxm;
struct Graph {
  struct point;
  struct edge;
  struct point {
    edge *first, *enow;
    int path;
    bool inq;
  } points[maxV + geps];
  struct edge {
    edge *next, *opp;
    point *to;
    int c, w;
  } edges[maxE * 2 + geps];
  int edgenum;
  point *st, *ed;
  int V;
  void initialize(int _V, int _st, int _ed) {
    V = _V, st = points + _st, ed = points + _ed;
    edgenum = -1;
    for (int i = 1; i <= V; i++) points[i].first = 0;
  }
  void addedge(point *x, point *y, int c, int w) {
    edge *e = edges + (++edgenum);
    e->to = y, e->c = c, e->w = w, e->next = x->first, x->first = e;
  }
  void add(int _x, int _y, int c, int w) {
    point *x = points + _x, *y = points + _y;
    addedge(x, y, c, w);
    addedge(y, x, 0, -w);
    edges[edgenum].opp = edges + edgenum - 1,
    edges[edgenum - 1].opp = edges + edgenum;
  }
  point *myque[maxV * maxV + geps];
  bool spfa() {
    int qhead = 0, qtail = -1;
    for (int i = 1; i <= V; i++) points[i].path = -inf, points[i].inq = false;
    myque[++qtail] = ed, ed->path = 0, ed->inq = true;
    while (qhead <= qtail) {
      point *now = myque[qhead++];
      now->inq = false;
      for (edge *e = now->first; e; e = e->next)
        if (e->opp->c > 0 && now->path + e->w > e->to->path) {
          e->to->path = e->w + now->path, e->to->enow = e->opp;
          if (!e->to->inq) {
            myque[++qtail] = e->to, e->to->inq = true;
            if (myque[qhead]->path > myque[qtail]->path)
              swap(myque[qhead], myque[qtail]);
          }
        }
    }
    return st->path > -inf;
  }
  int getflow(point *x, int cost, int lim, int &totcost) {
    if (x == ed) {
      totcost += lim * cost;
      return lim;
    }
    int ret = 0;
    x->inq = true;
    for (edge *e = x->enow; e; e = e->next)
      if (e->c > 0 && !e->to->inq && x->path + e->w == e->to->path) {
        int k = getflow(e->to, cost + e->w, min(lim - ret, e->c), totcost);
        ret += k, e->c -= k, e->opp->c += k;
      }
    x->inq = false;
    return ret;
  }
  int costflow() {
    int totcost = 0;
    while (spfa()) getflow(st, 0, inf, totcost);
    for (edge *e = st->first; e; e = e->next)
      if (e->c != 0) return -1;
    return totcost;
  }
} G;
int cnt[maxn + geps][27], a[maxn + geps];
int n;
string input;
void getcnt(int ind) {
  int len = input.size();
  for (int i = 0; i <= len - 1; i++) cnt[ind][input[i] - 'a' + 1]++;
}
void Init() {
  int len;
  cin >> input;
  getcnt(0);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> input >> a[i];
    getcnt(i);
  }
}
void solve() {
  int st = 26 + n + 1, ed = 26 + n + 2;
  G.initialize(ed, st, ed);
  for (int i = 1; i <= 26; i++) G.add(st, i, cnt[0][i], 0);
  for (int i = 1; i <= 26; i++)
    for (int j = 1; j <= n; j++) G.add(i, 26 + j, cnt[j][i], 0);
  for (int j = 1; j <= n; j++) G.add(26 + j, ed, a[j], j);
  printf("%d\n", G.costflow());
}
int main() {
  Init();
  solve();
  return 0;
}
