#include <bits/stdc++.h>
using namespace std;
const int N = (int)100;
const int A = (int)26;
const int SZ = (int)N + A + 1000;
struct edge {
  int a, b, can, cost;
  edge(int a, int b, int can, int cost) {
    edge ::a = a;
    edge ::b = b;
    edge ::can = can;
    edge ::cost = cost;
  }
};
int n, st, t, len, ans, dp[SZ], last[SZ], num[SZ], need[A], cnt[A];
string s;
vector<edge> e;
bool was[SZ];
void addEdge(int a, int b, int cost, int can) {
  if (can == 0) return;
  e.push_back(edge(a, b, can, cost));
  e.push_back(edge(b, a, 0, -cost));
}
bool iter() {
  memset(was, 0, sizeof(was));
  memset(last, 0, sizeof(last));
  dp[st] = 0;
  was[st] = true;
  for (int i = 0; i < n + A + 2; i++)
    for (int j = 0; j < (int)(e).size(); j++) {
      if (e[j].can == 0) continue;
      int a = e[j].a, b = e[j].b;
      if (was[a] && (!was[b] || dp[b] > dp[a] + e[j].cost)) {
        was[b] = true;
        dp[b] = dp[a] + e[j].cost;
        last[b] = a;
        num[b] = j;
      }
    }
  if (!was[t]) return false;
  int cur = t;
  while (cur != st) {
    e[num[cur]].can--;
    e[num[cur] ^ 1].can++;
    cur = last[cur];
  }
  ans += dp[t];
  return true;
}
int main() {
  cin >> s >> n;
  st = n + A;
  t = n + A + 1;
  for (int i = 0; i < (int)(s).size(); i++) {
    need[s[i] - 'a']++;
  }
  len = (int)(s).size();
  for (int i = 0; i < A; i++) addEdge(n + i, t, 0, need[i]);
  for (int i = 0; i < n; i++) {
    int a;
    memset(cnt, 0, sizeof(cnt));
    cin >> s >> a;
    addEdge(st, i, 0, a);
    for (int j = 0; j < (int)(s).size(); j++) cnt[s[j] - 'a']++;
    for (int j = 0; j < A; j++) addEdge(i, n + j, i + 1, cnt[j]);
  }
  int res = 0;
  while (iter()) {
    static int cnt = 0;
    cnt++;
    res++;
  }
  if (res < len)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
