#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int MaxN = 1005;
const int MaxE = MaxN * MaxN * 2;
const int Inf = 0x3F3F3F3F;
struct Edge {
  int v, cap, w;
  Edge *nxt, *inv;
} memo[MaxE], *cur, *g[MaxN], *pre[MaxN];
int cnt[26], q[MaxN], d[MaxN];
bool in[MaxN];
char buf[MaxN];
int n, len, m, s, t;
void init() {
  memset(g, 0, sizeof(g));
  cur = memo;
}
void add(int u, int v, int cap, int w) {
  cur->v = v, cur->cap = cap, cur->w = w, cur->nxt = g[u], cur->inv = cur + 1,
  g[u] = cur++;
  cur->v = u, cur->cap = 0, cur->w = -w, cur->nxt = g[v], cur->inv = cur - 1,
  g[v] = cur++;
}
bool spfa() {
  int f = 0, b = 0, u, v;
  for (int i = 0; i < n; ++i) {
    d[i] = Inf;
    in[i] = false;
  }
  d[s] = 0;
  q[b++] = s;
  while (f != b) {
    u = q[f++];
    if (f == MaxN) f = 0;
    in[u] = false;
    for (Edge* it = g[u]; it; it = it->nxt) {
      v = it->v;
      if (it->cap && d[v] - d[u] > it->w) {
        d[v] = d[u] + it->w;
        pre[v] = it;
        if (!in[v]) {
          in[v] = true;
          q[b++] = v;
          if (b == MaxN) b = 0;
        }
      }
    }
  }
  return d[t] < Inf;
}
int sol() {
  int flow = 0, cost = 0;
  int mn, u;
  while (spfa()) {
    mn = Inf;
    u = t;
    do {
      mn = min(pre[u]->cap, mn);
      u = pre[u]->inv->v;
    } while (u != s);
    u = t;
    do {
      pre[u]->cap -= mn;
      pre[u]->inv->cap += mn;
      u = pre[u]->inv->v;
    } while (u != s);
    cost += mn * d[t];
    flow += mn;
  }
  return flow == len ? cost : -1;
}
int main() {
  int w;
  while (scanf("%s", buf) == 1) {
    scanf("%d", &m);
    init();
    n = m + 28;
    s = 0;
    t = n - 1;
    len = strlen(buf);
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; buf[i]; ++i) ++cnt[buf[i] - 'a'];
    for (int i = 0; i < 26; ++i)
      if (cnt[i]) add(m + i + 1, t, cnt[i], 0);
    for (int i = 0; i < m; ++i) {
      scanf("%s%d", buf, &w);
      memset(cnt, 0, sizeof(cnt));
      add(s, i + 1, w, 0);
      for (int j = 0; buf[j]; ++j) ++cnt[buf[j] - 'a'];
      for (int j = 0; j < 26; ++j)
        if (cnt[j]) add(i + 1, m + j + 1, cnt[j], i + 1);
    }
    printf("%d\n", sol());
  }
  return 0;
}
