#include <bits/stdc++.h>
using namespace std;
struct MinCostMaxFlow {
  int N;
  vector<vector<long long> > cap, flow, cost;
  vector<int> found;
  vector<long long> 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 && 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(), 1123123123ll * 1123123123ll);
    fill(width.begin(), width.end(), 0);
    dist[s] = 0;
    width[s] = 1123123123ll * 1123123123ll;
    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++)
      pi[k] = min(pi[k] + dist[k], 1123123123ll * 1123123123ll);
    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);
  }
};
MinCostMaxFlow *G = NULL;
char T[111];
int n, a;
char S[111];
int tt[333];
int main() {
  scanf("%s", T);
  scanf("%d", &n);
  memset(tt, 0, sizeof(tt));
  for (int i = 0; i < strlen(T); i++) tt[T[i]]++;
  G = new MinCostMaxFlow(2 + n + 26);
  for (int i = 'a'; i <= 'z'; i++) {
    G->AddEdge(0, i - 'a' + 1, tt[i], 0);
  }
  for (int i = 0; i < n; i++) {
    scanf("%s", S);
    scanf("%d", &a);
    memset(tt, 0, sizeof(tt));
    for (int j = 0; j < strlen(S); j++) tt[S[j]]++;
    for (int j = 'a'; j <= 'z'; j++)
      if (tt[j] > 0) G->AddEdge(j - 'a' + 1, i + 26 + 1, tt[j], i + 1);
    G->AddEdge(i + 27, n + 1 + 26, a, 0);
  }
  pair<long long, long long> ans = G->GetMaxFlow(0, n + 1 + 26);
  if ((int)ans.first == strlen(T))
    printf("%I64d\n", ans.second);
  else
    printf("-1\n");
  return 0;
}
