#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, cap, cost, rev;
  edge(int _to, int _cap, int _cost, int _rev)
      : to(_to), cap(_cap), cost(_cost), rev(_rev) {}
};
struct cost {
  vector<edge> graph[50007];
  int pre[50007], pre_e[50007], inq[50007], F, C;
  int dist[50007];
  cost() {
    F = 0;
    C = 0;
    fill(graph, graph + 50007, vector<edge>());
  }
  void add(int from, int to, int cap, int cost) {
    graph[from].push_back(edge(to, cap, cost, graph[to].size()));
    graph[to].push_back(edge(from, 0, -cost, graph[from].size() - 1));
  }
  bool bfs(int ini, int fim) {
    fill(dist, dist + 50007, 1000000007);
    fill(inq, inq + 50007, 0);
    dist[ini] = 0;
    queue<int> q;
    q.push(ini);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      inq[u] = 0;
      for (int i = 0; i < graph[u].size(); i++) {
        int v = graph[u][i].to;
        int w = graph[u][i].cost;
        if (graph[u][i].cap > 0 && dist[v] > dist[u] + w) {
          pre[v] = u;
          pre_e[v] = i;
          dist[v] = dist[u] + w;
          if (!inq[v]) {
            inq[v] = true;
            q.push(v);
          }
        }
      }
    }
    return dist[fim] != 1000000007;
  }
  pair<int, int> flow(int ini, int fim) {
    while (bfs(ini, fim)) {
      int tf = 1000000007;
      for (int v = fim, u, l; v != ini; v = u) {
        u = pre[v];
        l = pre_e[v];
        tf = min(tf, graph[u][l].cap);
      }
      for (int v = fim, u, l; v != ini; v = u) {
        u = pre[v];
        l = pre_e[v];
        graph[u][l].cap -= tf;
        graph[v][graph[u][l].rev].cap += tf;
      }
      C += tf * dist[fim];
      F += tf;
    }
    return make_pair(F, C);
  }
};
int source = 50007 - 1;
int sink = 50007 - 2;
int freq[26];
int main() {
  cost custo = cost();
  string s;
  cin >> s;
  for (int i = 0; i < (int)s.size(); i++) {
    freq[s[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    custo.add(i, sink, freq[i], 0);
  }
  int id = 26;
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int aux = id;
    id++;
    int k;
    string t;
    cin >> t >> k;
    custo.add(source, aux, k, 0);
    for (int j = 0; j < (int)t.size(); j++) {
      custo.add(aux, t[j] - 'a', 1, i);
    }
  }
  pair<int, int> res = custo.flow(source, sink);
  if (res.first == (int)s.size())
    cout << res.second << endl;
  else
    cout << -1 << endl;
}
