#include <bits/stdc++.h>
using namespace std;
const int N = 204;
int n, m, k;
struct E {
  int next, to, val, cost;
} e[N * 34];
int head[N], tot = 0, st, ed;
void add(int x, int y, int z, int c) {
  e[tot] = E{y, head[x], z, c};
  head[x] = tot++;
  e[tot] = E{x, head[y], 0, -c};
  head[y] = tot++;
}
int c[27];
int flow = 0, ans = 0;
int pre[N], incf[N];
int d[N], vis[N], INF = 0x3f3f3f3f;
void update() {
  int x = ed;
  while (x != st) {
    int i = pre[x];
    e[i].val -= incf[ed];
    e[i ^ 1].val += incf[ed];
    x = e[i ^ 1].next;
  }
  flow += incf[ed];
  ans += d[ed] * incf[ed];
}
bool spfa() {
  queue<int> q;
  memset(d, 0x3f, sizeof(d));
  memset(vis, 0, sizeof(vis));
  q.push(st);
  d[st] = 0;
  vis[st] = 1;
  incf[st] = INF;
  while (!q.empty()) {
    int u = q.front();
    vis[u] = 0;
    q.pop();
    for (int i = head[u]; ~i; i = e[i].to) {
      if (!e[i].val) continue;
      int v = e[i].next;
      if (d[u] + e[i].cost < d[v]) {
        d[v] = d[u] + e[i].cost;
        incf[v] = min(incf[u], e[i].val);
        pre[v] = i;
        if (!vis[v]) {
          vis[v] = 1;
          q.push(v);
        }
      }
    }
  }
  return d[ed] != INF;
}
int main() {
  int n, q, x;
  memset(head, -1, sizeof(head));
  string s, t;
  cin >> s >> n;
  for (int i = 1; i <= n; i++) {
    cin >> t >> x;
    add(0, i, x, i);
    memset(c, 0, sizeof(c));
    for (char ch : t) ++c[ch - 'a'];
    for (int j = 0; j < 26; j++)
      if (c[j]) add(i, n + j + 1, c[j], 0);
  }
  st = 0;
  ed = n + 26 + 1;
  memset(c, 0, sizeof(c));
  for (char ch : s) ++c[ch - 'a'];
  for (int j = 0; j < 26; j++)
    if (c[j]) add(n + j + 1, ed, c[j], 0);
  while (spfa()) update();
  if (flow != s.size()) ans = -1;
  printf("%d\n", ans);
}
