#include <bits/stdc++.h>
using namespace std;
struct mincostmaxflow {
  int n;
  vector<vector<long long int> > cap, flow, cost;
  vector<int> found;
  vector<long long int> dist, pi, width;
  vector<pair<int, int> > dad;
  mincostmaxflow(int n)
      : n(n),
        cap(n, vector<long long>(n)),
        flow(n, vector<long long>(n)),
        cost(n, vector<long long>(n)),
        found(n),
        dist(n),
        pi(n),
        width(n),
        dad(n) {}
  void addedge(int from, int to, long long cap, long long cost) {
    this->cap[from][to] = cap;
    this->cost[from][to] = cost;
  }
  void relax(int s, int k, long long cap, long long cost, int dir) {
    long long val = dist[s] + pi[s] - pi[k] + cost;
    if (cap and val < dist[k]) {
      dist[k] = val;
      dad[k] = make_pair(s, dir);
      width[k] = min(cap, width[s]);
    }
  }
  long long dijkstra(int s, int t) {
    fill(found.begin(), found.end(), false);
    fill(dist.begin(), dist.end(), 10000000LL);
    fill(width.begin(), width.end(), 0);
    dist[s] = 0;
    width[s] = 10000000LL;
    while (s != -1) {
      int best = -1;
      found[s] = true;
      for (int k = 0; k < n; k++) {
        if (found[k]) continue;
        relax(s, k, cap[s][k] - flow[s][k], cost[s][k], 1);
        relax(s, k, flow[k][s], -cost[k][s], -1);
        if (best == -1 or dist[k] < dist[best]) best = k;
      }
      s = best;
    }
    for (int k = 0; k < n; k++) pi[k] = min(pi[k] + dist[k], 10000000LL);
    return width[t];
  }
  pair<long long, long long> getmaxflow(int s, int t) {
    long long totflow = 0, totcost = 0;
    while (long long amt = dijkstra(s, t)) {
      totflow += amt;
      for (int x = t; x != s; x = dad[x].first)
        if (dad[x].second == 1) {
          flow[dad[x].first][x] += amt;
          totcost += amt * cost[dad[x].first][x];
        } else {
          flow[x][dad[x].first] -= amt;
          totcost -= amt * cost[x][dad[x].first];
        }
    }
    return make_pair(totflow, totcost);
  }
};
string s[1000], t;
int a[1000], cnt[100];
int func(int n) {
  for (int i = 0; i < t.size(); i++) cnt[t[i] - 'a' + 1]++;
  int source = 0;
  int sink = 2 * n + 27;
  mincostmaxflow graph(2 * n + 50);
  for (int i = 1; i <= n; i++) {
    graph.addedge(i, i + n, a[i], 0);
    graph.addedge(source, i, 10000000LL, 0);
  }
  for (int i = 1; i <= 26; i++) graph.addedge(n + n + i, sink, cnt[i], 0);
  for (int i = 1; i <= n; i++) {
    int cn[30] = {0};
    for (int j = 0; j < s[i].size(); j++) cn[s[i][j] - 'a' + 1]++;
    for (int j = 1; j <= 26; j++) graph.addedge(n + i, n + n + j, cn[j], i);
  }
  pair<long long, long long> ans = graph.getmaxflow(source, sink);
  if (ans.first != t.size()) return -1;
  return ans.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> t;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i] >> a[i];
  cout << func(n) << endl;
  return 0;
}
