#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;
class MinCostFlow {
  class edge {
   public:
    int to, cap, cost, rev;
    edge() {}
    edge(int to, int cap, int cost, int rev)
        : to(to), cap(cap), cost(cost), rev(rev) {}
  };
  int infinity;
  int SIZE;
  vector<int> dist;
  vector<int> h;
  vector<int> prevv;
  vector<int> preve;
  vector<vector<edge> > G;

 public:
  MinCostFlow(int V)
      : SIZE(V),
        dist(vector<int>(V)),
        h(vector<int>(V)),
        prevv(vector<int>(V)),
        preve(vector<int>(V)),
        G(vector<vector<edge> >(V)) {
    infinity = 1000 * 1000 * 1000 + 7;
  }
  void add_edge(int from, int to, int cap, int cost) {
    G[from].push_back(edge(to, cap, cost, G[to].size()));
    G[to].push_back(edge(from, 0, -cost, G[from].size() - 1));
  }
  void init(int size = 0) {
    if (size > 0) {
      dist.resize(size);
      h.resize(size);
      prevv.resize(size);
      preve.resize(size);
      G.resize(size);
    }
    for (int i = 0; i < (int)G.size(); i++) G[i].clear();
  }
  int min_cost_flow(int s, int t, int f) {
    int res = 0;
    fill(h.begin(), h.end(), 0);
    while (f > 0) {
      priority_queue<pair<int, int>, vector<pair<int, int> >,
                     greater<pair<int, int> > >
          que;
      fill(dist.begin(), dist.end(), infinity);
      dist[s] = 0;
      que.push(pair<int, int>(0, s));
      while (!que.empty()) {
        pair<int, int> p = que.top();
        que.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;
        for (int i = 0; i < (int)G[v].size(); i++) {
          edge &e = G[v][i];
          if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
            dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
            prevv[e.to] = v;
            preve[e.to] = i;
            que.push(pair<int, int>(dist[e.to], e.to));
          }
        }
      }
      if (dist[t] == infinity) return -1;
      for (int v = 0; v < SIZE; v++) h[v] += dist[v];
      int d = f;
      for (int v = t; v != s; v = prevv[v]) {
        d = min(d, G[prevv[v]][preve[v]].cap);
      }
      f -= d;
      res += d * h[t];
      for (int v = t; v != s; v = prevv[v]) {
        edge &e = G[prevv[v]][preve[v]];
        e.cap -= d;
        G[v][e.rev].cap += d;
      }
    }
    return res;
  }
};
const int maxn = 110;
string str[maxn];
int a[maxn];
int main() {
  int n;
  string T;
  cin >> T;
  cin >> n;
  int s = n + 26;
  int t = s + 1;
  MinCostFlow mcf(t + 1);
  for (int i = 0; i < (int)(n); i++) {
    cin >> str[i] >> a[i];
    mcf.add_edge(s, i, a[i], 0);
  }
  for (int i = 0; i < (int)(26); i++) {
    int num = count(T.begin(), T.end(), 'a' + i);
    mcf.add_edge(n + i, t, num, 0);
    for (int j = 0; j < (int)(n); j++) {
      int snum = count(str[j].begin(), str[j].end(), 'a' + i);
      if (snum > 0) {
        mcf.add_edge(j, n + i, snum, (j + 1));
        num -= snum;
      }
    }
    if (num > 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << mcf.min_cost_flow(s, t, (int)T.size()) << endl;
  ;
  return 0;
}
