#include <bits/stdc++.h>
const long long INF = (long long)1e18 + 123;
const int inf = (int)2e9 + 123;
const int mod = 1e9 + 7;
using namespace std;
int n;
vector<int> g[100011];
struct edge {
  int f, to, cost, cap, fl;
  edge() {
    f = to = 0;
    cost = cap = 0;
    fl = 0;
  }
  edge(int a, int b, int c, int d) {
    f = a;
    to = b;
    cost = d;
    cap = c;
    fl = 0;
  }
};
int s, t, d[511], p[511];
vector<edge> e;
int size = 0;
bool ford_bellman() {
  for (int i = s + 1; i <= t; i++) {
    d[i] = inf;
    p[i] = 0;
  }
  p[s] = d[s] = 0;
  bool did = 1;
  while (did) {
    did = 0;
    for (int i = 0; i < e.size(); i++) {
      edge x = e[i];
      int fr = x.f, to = x.to;
      if (d[fr] == inf || x.fl >= x.cap) continue;
      if (d[to] > d[fr] + x.cost) {
        p[to] = i;
        d[to] = d[fr] + x.cost;
        did = 1;
      }
    }
  }
  return (d[t] < inf);
}
long long dinic(int k) {
  long long ans = 0;
  int flow = 0;
  for (int step = 1; step < t; step++) {
    if (!ford_bellman()) break;
    int v = t, fl = inf;
    while (v != s) {
      edge x = e[p[v]];
      fl = min(fl, x.cap - x.fl);
      v = x.f;
    }
    v = t;
    while (v != s) {
      e[p[v]].fl += fl;
      e[(p[v] ^ 1)].fl -= fl;
      ans += 1ll * fl * e[p[v]].cost;
      v = e[p[v]].f;
    }
    flow += fl;
    if (!fl) break;
  }
  if (flow < k) return -1;
  return ans;
}
string a, b[111];
int c[111];
int cnt[111];
int main() {
  unsigned int FOR;
  asm("rdtsc" : "=A"(FOR));
  srand(FOR);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> a >> n;
  s = t = 1;
  for (int i = 1; i <= n; i++) {
    cin >> b[i] >> c[i];
    t++;
    e.push_back(edge(s, t, c[i], 0));
    e.push_back(edge(t, s, 0, 0));
    size += 2;
  }
  for (int i = 1; i <= n; i++) {
    memset(cnt, 0, sizeof(cnt));
    for (int j = 0; j < b[i].size(); j++) {
      cnt[b[i][j] - 'a']++;
    }
    for (int j = 0; j < 26; j++) {
      if (cnt[j] > 0) {
        e.push_back(edge(i + 1, t + j + 1, cnt[j], i));
        e.push_back(edge(t + j + 1, i + 1, 0, -i));
        size += 2;
      }
    }
  }
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < a.size(); i++) {
    cnt[a[i] - 'a']++;
  }
  t += 27;
  for (int i = 0; i < 26; i++) {
    int x = i + n + 2;
    if (cnt[i] > 0) {
      e.push_back(edge(x, t, cnt[i], 0));
      e.push_back(edge(t, x, 0, 0));
      size += 2;
    }
  }
  cout << dinic((int)a.size());
  return 0;
}
