#include <bits/stdc++.h>
using namespace std;
const long long INF = numeric_limits<long long>::max() / 4;
struct MinCostFlow {
  int n;
  vector<vector<long long> > capacities, flows, costs;
  vector<long long> dists, potentials, widths;
  vector<pair<int, bool> > parents;
  vector<bool> visited;
  MinCostFlow(int n)
      : n(n),
        capacities(n, vector<long long>(n, 0)),
        flows(n, vector<long long>(n, 0)),
        costs(n, vector<long long>(n)),
        dists(n),
        potentials(n, 0),
        widths(n),
        parents(n),
        visited(n) {}
  void add_edge(int from, int to, long long cap, long long cost) {
    capacities[from][to] = cap;
    costs[from][to] = cost;
  }
  void relax(int s, int k, long long cap, long long cost, bool dir) {
    long long reduced = dists[s] + potentials[s] - potentials[k] + cost;
    if (cap && reduced < dists[k]) {
      dists[k] = reduced;
      parents[k] = make_pair(s, dir);
      widths[k] = min(cap, widths[s]);
    }
  }
  long long shortest_path(int s, int t) {
    fill(visited.begin(), visited.end(), false);
    fill(dists.begin(), dists.end(), INF);
    fill(widths.begin(), widths.end(), 0);
    dists[s] = 0;
    widths[s] = INF;
    while (s != -1) {
      int best = -1;
      visited[s] = true;
      for (int k = 0; k < n; k++) {
        if (visited[k]) continue;
        relax(s, k, capacities[s][k] - flows[s][k], costs[s][k], true);
        relax(s, k, flows[k][s], -costs[k][s], false);
        if (best == -1 || dists[k] < dists[best]) best = k;
      }
      s = best;
    }
    for (int k = 0; k < n; k++)
      potentials[k] = min(potentials[k] + dists[k], INF);
    return widths[t];
  }
  pair<long long, long long> get_flow(int s, int t) {
    long long total_flow = 0, total_cost = 0;
    while (long long amnt = shortest_path(s, t)) {
      total_flow += amnt;
      for (int v = t; v != s; v = parents[v].first) {
        if (parents[v].second) {
          flows[parents[v].first][v] += amnt;
          total_cost += amnt * costs[parents[v].first][v];
        } else {
          flows[v][parents[v].first] -= amnt;
          total_cost -= amnt * costs[v][parents[v].first];
        }
      }
    }
    return make_pair(total_flow, total_cost);
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, tlen;
  string t;
  vector<string> ss(100);
  vector<int> as(100);
  cin >> t >> n;
  tlen = t.size();
  for (int i = 0; i < n; i++) cin >> ss[i] >> as[i];
  int sink = 1 + n + 26;
  MinCostFlow solver(sink + 1);
  for (int i = 0; i < n; i++) solver.add_edge(0, i + 1, as[i], i + 1);
  for (int i = 1, c = 'a'; i <= 26; i++, c++) {
    for (int j = 0; j < n; j++) {
      int scnt = 0;
      int slen = ss[j].length();
      for (int k = 0; k < slen; k++) {
        if (ss[j][k] == c) scnt++;
      }
      solver.add_edge(j + 1, sink - i, scnt, 0);
    }
    int tcnt = 0;
    for (int k = 0; k < tlen; k++) {
      if (t[k] == c) tcnt++;
    }
    solver.add_edge(sink - i, sink, tcnt, 0);
  }
  pair<long long, long long> ans = solver.get_flow(0, sink);
  cout << (ans.first == tlen ? ans.second : -1) << endl;
  return 0;
}
