#include <bits/stdc++.h>
using namespace std;
const int N = 10050;
const int oo = 0x3f3f3f3f;
struct edge {
  int v, cost, cap, flow, back;
  edge() {}
  edge(int vv, int cc, int ccap, int bb)
      : v(vv), cost(cc), cap(ccap), flow(0), back(bb) {}
};
vector<edge> adj[N];
int so, si, n, m;
int prv[N], prv_edge[N], dist[N], phi[N];
void add_edge(int u, int v, int cost, int cap) {
  edge e1(v, cost, cap, adj[v].size());
  edge e2(u, -cost, 0, adj[u].size());
  adj[u].push_back(e1);
  adj[v].push_back(e2);
}
void init() {
  for (int i = 0; i < N; i++) adj[i].clear();
}
bool dijkstra() {
  memset(prv, -1, sizeof(prv));
  memset(prv_edge, -1, sizeof prv_edge);
  fill(dist, dist + n, oo);
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  dist[so] = 0;
  pq.push(pair<int, int>(0, so));
  bool ret = false;
  while (!pq.empty()) {
    int u = pq.top().second;
    int du = pq.top().first;
    pq.pop();
    if (u == si) {
      ret = true;
    }
    if (du > dist[u]) continue;
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i].v;
      if (adj[u][i].cap - adj[u][i].flow <= 0) continue;
      if (dist[v] > dist[u] + phi[u] - phi[v] + adj[u][i].cost) {
        dist[v] = dist[u] + phi[u] - phi[v] + adj[u][i].cost;
        prv[v] = u;
        prv_edge[v] = i;
        pq.push(pair<int, int>(dist[v], v));
      }
    }
  }
  for (int i = 0; i < N; i++)
    if (phi[i] < oo && dist[i] < oo) phi[i] += dist[i];
  return ret;
}
pair<int, int> aug() {
  int mw = oo;
  for (int u = si; u != so; u = prv[u]) {
    mw = min(mw, adj[prv[u]][prv_edge[u]].cap - adj[prv[u]][prv_edge[u]].flow);
  }
  int r = 0;
  for (int u = si; u != so; u = prv[u]) {
    adj[prv[u]][prv_edge[u]].flow += mw;
    adj[u][adj[prv[u]][prv_edge[u]].back].flow -= mw;
    r += adj[prv[u]][prv_edge[u]].cost * mw;
  }
  return pair<int, int>(r, mw);
}
pair<int, int> mbm() {
  pair<int, int> r(0, 0);
  memset(phi, 0, sizeof phi);
  while (dijkstra()) {
    pair<int, int> rinc = aug();
    r.first += rinc.first;
    r.second += rinc.second;
  }
  return r;
}
int main(void) {
  string a;
  cin >> a;
  so = 0, si = 1;
  for (int i = 0; i < a.size(); i++) {
    add_edge(so, i + 2, 0, 1);
  }
  int nn;
  n = a.size() + 2;
  cin >> nn;
  vector<int> cm;
  for (int i = 0; i < nn; i++) {
    string tmp;
    cin >> tmp;
    int x;
    cin >> x;
    add_edge(n, si, 0, x);
    int ssi = n;
    n++;
    for (int j = 0; j < tmp.size(); j++) {
      for (int h = 0; h < a.size(); h++)
        if (a[h] == tmp[j]) add_edge(h + 2, n + j, i + 1, 1);
      add_edge(n + j, ssi, 0, 1);
    }
    n += tmp.size();
    cm.push_back(x);
  }
  pair<int, int> ret = mbm();
  if (ret.second < a.size())
    cout << "-1\n";
  else
    cout << ret.first << "\n";
  return 0;
}
