#include <bits/stdc++.h>
using namespace std;
struct MinCostMaxFlow {
  static const int MAXV = 20010;
  static const int INFf = 1000000;
  struct Edge {
    int v, cap;
    int w;
    int rev;
    Edge() {}
    Edge(int t2, int t3, int t4, int t5) : v(t2), cap(t3), w(t4), rev(t5) {}
  };
  int V, s, t;
  vector<Edge> g[MAXV];
  void init(int n) {
    V = n + 2;
    s = n + 1, t = n + 2;
    for (int i = 0; i <= V; i++) g[i].clear();
  }
  void addEdge(int a, int b, int cap, int w) {
    g[a].push_back(Edge(b, cap, w, (int)g[b].size()));
    g[b].push_back(Edge(a, 0, -w, (int)g[a].size() - 1));
  }
  int d[MAXV];
  int id[MAXV], mom[MAXV];
  bool inqu[MAXV];
  queue<int> q;
  int solve(int ob) {
    int mxf = 0;
    int mnc = 0;
    while (1) {
      fill(d, d + 1 + V, 1e9);
      fill(inqu, inqu + 1 + V, 0);
      fill(mom, mom + 1 + V, -1);
      mom[s] = s;
      d[s] = 0;
      q.push(s);
      inqu[s] = 1;
      while (q.size()) {
        int u = q.front();
        q.pop();
        inqu[u] = 0;
        for (int i = 0; i < (int)g[u].size(); i++) {
          Edge &e = g[u][i];
          int v = e.v;
          if (e.cap > 0 && d[v] > d[u] + e.w) {
            d[v] = d[u] + e.w;
            mom[v] = u;
            id[v] = i;
            if (!inqu[v]) q.push(v), inqu[v] = 1;
          }
        }
      }
      if (mom[t] == -1) break;
      int df = INFf;
      for (int u = t; u != s; u = mom[u]) df = min(df, g[mom[u]][id[u]].cap);
      for (int u = t; u != s; u = mom[u]) {
        Edge &e = g[mom[u]][id[u]];
        e.cap -= df;
        g[e.v][e.rev].cap += df;
      }
      mxf += df;
      mnc += df * d[t];
    }
    if (mxf != ob) return -1;
    return mnc;
  }
} g;
int main() {
  g.init(20000);
  string s, t;
  cin >> t;
  for (char c : t) {
    g.addEdge(c - 'a', g.t, 1, 0);
  }
  int n, a;
  cin >> n;
  for (int i = 1, temp = 30 + n + 1; i <= n; i++) {
    cin >> s >> a;
    g.addEdge(g.s, i + 27, a, i);
    for (int j = 0; j < s.length(); j++) {
      g.addEdge(temp + j, s[j] - 'a', 1, 0);
      g.addEdge(i + 27, temp + j, 1, 0);
    }
    temp += s.length();
  }
  cout << g.solve(t.length()) << endl;
  return 0;
}
