#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e12;
struct MinCostMaxFlow {
  int N;
  vector<vector<long long> > cap, flow, cost;
  vector<int> found;
  vector<long long> dist, fpi, 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),
        fpi(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] + fpi[s] - fpi[k] + cost;
    if (cap && 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(), INF);
    fill(width.begin(), width.end(), 0);
    dist[s] = 0;
    width[s] = INF;
    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 || dist[k] < dist[best]) best = k;
      }
      s = best;
    }
    for (int k = 0; k < N; k++) fpi[k] = min(fpi[k] + dist[k], INF);
    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 first = t; first != s; first = dad[first].first) {
        if (dad[first].second == 1) {
          flow[dad[first].first][first] += amt;
          totcost += amt * cost[dad[first].first][first];
        } else {
          flow[first][dad[first].first] -= amt;
          totcost -= amt * cost[first][dad[first].first];
        }
      }
    }
    return make_pair(totflow, totcost);
  }
};
long long cnt[26];
int main() {
  long long sz;
  string s;
  cin >> s;
  sz = s.size();
  memset(cnt, 0, sizeof(cnt));
  for (long long i = (0); i < (s.size()); i++) cnt[s[i] - 'a']++;
  long long N;
  scanf("%lld", &N);
  MinCostMaxFlow F(N + 40);
  long long src = 0, snk = N + 27;
  for (long long i = (0); i < (26); i++) {
    F.AddEdge(N + 1 + i, snk, cnt[i], 0);
  }
  for (long long i = (1); i < (N + 1); i++) {
    cin >> s;
    long long lmt;
    scanf("%lld", &lmt);
    F.AddEdge(src, i, lmt, i);
    memset(cnt, 0, sizeof(cnt));
    for (long long j = (0); j < (s.size()); j++) cnt[s[j] - 'a']++;
    for (long long j = (0); j < (26); j++) {
      F.AddEdge(i, N + 1 + j, cnt[j], 0);
    }
  }
  pair<long long, long long> flo = F.GetMaxFlow(src, snk);
  if (flo.first != sz)
    printf("-1\n");
  else
    printf("%lld\n", flo.second);
}
