#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)333;
const int mod = (int)1e9 + 7;
const double pi = acos(-1.0);
int n;
struct edge {
  int u, v, flow, cap, cost;
  edge() {}
  edge(int _u, int _v, int _flow, int _cap, int _cost) {
    u = _u;
    v = _v;
    flow = _flow;
    cost = _cost;
    cap = _cap;
  }
};
int was[maxn], d[maxn], p[maxn], second, t;
vector<int> g[maxn];
vector<edge> e;
void add(int u, int v, int cap, int cost) {
  e.push_back(edge(u, v, 0, cap, cost));
  g[u].push_back(((int)(e).size()) - 1);
  e.push_back(edge(v, u, 0, 0, -cost));
  g[v].push_back(((int)(e).size()) - 1);
}
pair<int, int> mcmf() {
  pair<int, int> ans = make_pair(0, 0);
  while (1) {
    queue<int> q;
    memset(was, 0, sizeof(was));
    for (int i = (0); i <= (maxn - 1); ++i) d[i] = INT_MAX;
    d[second] = 0;
    q.push(second);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      was[v] = 0;
      for (int idx : g[v]) {
        int to = e[idx].v, cap = e[idx].cap, flow = e[idx].flow,
            cost = e[idx].cost;
        if (cap == flow) continue;
        if (d[to] > d[v] + cost) {
          d[to] = d[v] + cost;
          p[to] = idx;
          if (!was[to]) was[to] = 1, q.push(to);
        }
      }
    }
    if (d[t] == INT_MAX) break;
    int mn = INT_MAX, cur = t;
    while (cur != second) {
      mn = min(mn, e[p[cur]].cap - e[p[cur]].flow);
      cur = e[p[cur]].u;
    }
    ans.first += mn;
    ans.second += (mn * d[t]);
    cur = t;
    while (cur != second) {
      e[p[cur]].flow += mn;
      e[p[cur] ^ 1].flow -= mn;
      cur = e[p[cur]].u;
    }
  }
  return ans;
}
string need;
int cnt[27];
int main() {
  cin >> need >> n;
  second = n + 26, t = n + 27;
  for (auto x : need) cnt[x - 'a']++;
  for (int i = (0); i <= (25); ++i) add(second, n + i, cnt[i], 0);
  for (int i = (1); i <= (n); ++i) {
    string cur;
    int x;
    cin >> cur >> x;
    add(i - 1, t, x, i);
    for (int ch = (0); ch <= (25); ++ch) cnt[ch] = 0;
    for (auto x : cur) cnt[x - 'a']++;
    for (int ch = (0); ch <= (25); ++ch) add(ch + n, i - 1, cnt[ch], 0);
  }
  pair<int, int> ans = mcmf();
  if (ans.first < ((int)(need).size()))
    cout << -1;
  else
    cout << ans.second;
}
