#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int MAX_N = 40000;
struct edge {
  int b, u, c, f, back;
};
vector<vector<edge> > g;
int d[MAX_N], p[MAX_N], phi[MAX_N], p_edge[MAX_N];
set<pair<int, int> > q;
inline void add_edge(int a, int b, int u, int c) {
  edge r1 = {b, u, c, 0, (int)g[b].size()};
  edge r2 = {a, 0, -c, 0, (int)g[a].size()};
  g[a].push_back(r1);
  g[b].push_back(r2);
}
int NEEDED;
int min_cost(int source, int sink, int vertexes, vector<vector<edge> > &g) {
  int flow = 0, cost = 0;
  memset(d, 0, sizeof(d));
  memset(p, -1, sizeof(p));
  memset(phi, 0, sizeof(phi));
  for (;;) {
    for (int i = 0; i < vertexes; ++i) phi[i] = d[i];
    q.clear();
    q.insert(make_pair(0, source));
    memset(d, 63, vertexes * sizeof(int));
    d[source] = 0;
    for (;;) {
      if (q.empty()) break;
      int v = q.begin()->second;
      q.erase(q.begin());
      for (int j = 0; j < (int)g[v].size(); ++j)
        if (g[v][j].f < g[v][j].u) {
          int to = g[v][j].b;
          int nl = d[v] + g[v][j].c + phi[v] - phi[to];
          if (nl < d[to]) {
            q.erase(make_pair(d[to], to));
            d[to] = nl;
            q.insert(make_pair(d[to], to));
            p_edge[to] = j;
            p[to] = v;
          }
        }
    }
    if (d[sink] >= inf) break;
    int addflow = inf;
    for (int v = sink; v != source; v = p[v]) {
      int pv = p[v];
      int pr = p_edge[v];
      addflow = min(addflow, g[pv][pr].u - g[pv][pr].f);
    }
    for (int v = sink; v != source; v = p[v]) {
      int pv = p[v];
      int pr = p_edge[v], r = g[pv][pr].back;
      g[pv][pr].f += addflow;
      g[v][r].f -= addflow;
      cost += g[pv][pr].c * addflow;
    }
    flow += addflow;
  }
  if (flow < NEEDED) return -1;
  return cost;
}
int need[222];
int main() {
  string t;
  cin >> t;
  NEEDED = (int)t.size();
  memset(need, 0, sizeof(need));
  for (int i = 0; i <= (int)t.size() - 1; ++i) need[t[i] - 'a']++;
  g.resize(40000);
  for (int i = 0; i <= 40000 - 1; ++i) g[i].clear();
  int source = 0, sink = 27;
  for (int i = 1; i <= 26; ++i) add_edge(i, sink, need[i - 1], 0);
  int sz = 28;
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    string s;
    int cnt;
    cin >> s >> cnt;
    int cur = sz++;
    add_edge(source, cur, cnt, 0);
    for (int j = 0; j <= (int)s.size() - 1; ++j) {
      int to = sz++;
      add_edge(cur, to, 1, i);
      add_edge(to, s[j] - 'a' + 1, 1, 0);
    }
  }
  int ans = min_cost(source, sink, 100 + sz, g);
  cout << ans << endl;
}
