#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double PI = acos(-1);
const double EPS = 1e-8;
struct Edge {
  int src, dst;
  int capacity, cost;
  int rev;
  Edge(int src, int dst, int capacity, int cost)
      : src(src), dst(dst), capacity(capacity), cost(cost) {}
  Edge(int src, int dst, int capacity, int cost, int rev)
      : src(src), dst(dst), capacity(capacity), cost(cost), rev(rev) {}
};
bool operator<(const Edge &e, const Edge &f) {
  return e.cost != f.cost ? e.cost > f.cost
         : e.src != f.src ? e.src < f.src
                          : e.dst < f.dst;
}
void add_edge(vector<vector<Edge> > &g, int s, int d, int cap, int cost) {
  g[s].push_back(Edge(s, d, cap, cost));
  g[d].push_back(Edge(d, s, 0, -cost));
}
pair<int, int> minimumCostFlow(const vector<vector<Edge> > &g, int s, int t) {
  const int n = g.size();
  vector<vector<int> > capacity(n, vector<int>(n)), cost(n, vector<int>(n)),
      flow(n, vector<int>(n));
  for (int u = 0; u < (int)n; ++u)
    for (__typeof((g[u]).begin()) e = (g[u]).begin(); e != (g[u]).end(); ++e) {
      capacity[e->src][e->dst] += e->capacity;
      cost[e->src][e->dst] += e->cost;
    }
  pair<int, int> total;
  vector<int> h(n, INF);
  h[s] = 0;
  for (int k = 0; k < (int)n; ++k)
    for (int i = 0; i < (int)n; ++i)
      for (__typeof((g[i]).begin()) e = (g[i]).begin(); e != (g[i]).end(); ++e)
        if (capacity[e->src][e->dst])
          h[e->dst] = min(h[e->dst], h[e->src] + cost[e->src][e->dst]);
  for (int F = INF; F > 0;) {
    vector<int> d(n, INF);
    d[s] = 0;
    vector<int> p(n, -1);
    priority_queue<Edge> Q;
    for (Q.push(Edge(-2, s, 0, 0)); !Q.empty();) {
      Edge e = Q.top();
      Q.pop();
      if (p[e.dst] != -1) continue;
      p[e.dst] = e.src;
      for (__typeof((g[e.dst]).begin()) f = (g[e.dst]).begin();
           f != (g[e.dst]).end(); ++f)
        if ((capacity[f->src][f->dst] - flow[f->src][f->dst]) > 0) {
          if (d[f->dst] >
              d[f->src] + (cost[f->src][f->dst] + h[f->src] - h[f->dst])) {
            d[f->dst] =
                d[f->src] + (cost[f->src][f->dst] + h[f->src] - h[f->dst]);
            Q.push(Edge(f->src, f->dst, 0, d[f->dst]));
          }
        }
    }
    if (p[t] == -1) break;
    int f = F;
    for (int u = t; u != s; u = p[u])
      f = min(f, (capacity[p[u]][u] - flow[p[u]][u]));
    for (int u = t; u != s; u = p[u]) {
      total.first += f * cost[p[u]][u];
      flow[p[u]][u] += f;
      flow[u][p[u]] -= f;
    }
    F -= f;
    total.second += f;
    for (int u = 0; u < (int)n; ++u)
      if (h[u] != INF) h[u] += d[u];
  }
  return total;
}
int n;
int LETTER(int i) { return n + i; }
int NODE(int i) { return i; }
int SOURCE() { return n + 26; }
int SINK() { return n + 27; }
int main() {
  string s;
  cin >> s;
  cin >> n;
  vector<vector<Edge> > g(n + 28);
  for (int i = 0; i < (int)n; ++i) {
    string t;
    int a;
    cin >> t >> a;
    map<int, int> mp;
    for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); ++it)
      mp[*it - 'a']++;
    for (__typeof((mp).begin()) it = (mp).begin(); it != (mp).end(); ++it) {
      add_edge(g, NODE(i), LETTER(it->first), it->second, 0);
    }
    add_edge(g, SOURCE(), NODE(i), a, i + 1);
  }
  map<int, int> mp;
  for (__typeof((s).begin()) it = (s).begin(); it != (s).end(); ++it)
    mp[*it - 'a']++;
  for (__typeof((mp).begin()) it = (mp).begin(); it != (mp).end(); ++it) {
    add_edge(g, LETTER(it->first), SINK(), it->second, 0);
  }
  pair<int, int> p = minimumCostFlow(g, SOURCE(), SINK());
  if (p.second == s.size()) {
    cout << p.first << endl;
  } else {
    cout << -1 << endl;
  }
}
