#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
struct Edge {
  int src, dst, rev;
  int capacity, cost;
  Edge(int src_, int dst_, int capacity_, int cost_)
      : src(src_), dst(dst_), capacity(capacity_), cost(cost_) {}
};
pair<int, int> min_cost_flow(vector<vector<Edge> > &g, int s, int t, int f) {
  int V = g.size();
  vector<int> dist(V);
  vector<int> prevV(V), prevE(V);
  pair<int, int> r = make_pair((0), (0));
  while (f > 0) {
    fill((dist).begin(), (dist).end(), INF);
    dist[s] = 0;
    bool update;
    do {
      update = false;
      for (int(v) = 0; (v) < (int)(V); ++(v)) {
        if (dist[v] == INF) continue;
        for (int(i) = 0; (i) < (int)(g[v].size()); ++(i)) {
          const Edge &e = g[v][i];
          if (e.capacity > 0 && dist[e.dst] > dist[v] + e.cost) {
            dist[e.dst] = dist[v] + e.cost;
            prevV[e.dst] = v;
            prevE[e.dst] = i;
            update = true;
          }
        }
      }
    } while (update);
    if (dist[t] == INF) break;
    int d = f;
    for (int v = t; v != s; v = prevV[v])
      d = min(d, g[prevV[v]][prevE[v]].capacity);
    f -= d;
    r.first += d * dist[t];
    r.second += d;
    for (int v = t; v != s; v = prevV[v]) {
      Edge &e = g[prevV[v]][prevE[v]];
      e.capacity -= d;
      g[v][e.rev].capacity += d;
    }
  }
  return r;
}
vector<vector<Edge> > createRev(const vector<vector<Edge> > &g) {
  vector<vector<Edge> > r(g.size());
  for (typeof((g).begin()) i = ((g).begin()); i != (g).end(); ++i)
    for (typeof((*i).begin()) j = ((*i).begin()); j != (*i).end(); ++j) {
      r[j->src].push_back(*j);
      r[j->dst].push_back(Edge(j->dst, j->src, 0, -j->cost));
      r[j->src].back().rev = r[j->dst].size() - 1;
      r[j->dst].back().rev = r[j->src].size() - 1;
    }
  return r;
}
char b[111];
int main() {
  scanf("%s", b);
  string t(b);
  int n;
  scanf("%d", &n);
  vector<vector<Edge> > g(n + 26 + 2);
  int src = n + 26, dst = n + 26 + 1;
  map<char, int> m;
  for (typeof((t).begin()) i = ((t).begin()); i != (t).end(); ++i) m[*i]++;
  for (typeof((m).begin()) i = ((m).begin()); i != (m).end(); ++i)
    g[src].push_back(Edge(src, n + (i->first - 'a'), i->second, -1000000));
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    m.clear();
    scanf("%s", b);
    string s(b);
    for (typeof((s).begin()) j = ((s).begin()); j != (s).end(); ++j) m[*j]++;
    int a;
    scanf("%d", &a);
    for (typeof((m).begin()) j = ((m).begin()); j != (m).end(); ++j) {
      int x = n + (j->first - 'a');
      g[x].push_back(Edge(x, i, j->second, i + 1));
    }
    g[i].push_back(Edge(i, dst, a, 0));
  }
  vector<vector<Edge> > g2 = createRev(g);
  pair<int, int> p = min_cost_flow(g2, src, dst, t.size());
  cerr << "p: " << p.first << ", " << p.second << endl;
  int r = -2;
  if (p.second != t.size()) {
    r = -1;
  } else {
    r = p.first - (-1000000 * t.size());
  }
  printf("%d\n", r);
  return 0;
}
