#include <bits/stdc++.h>
using namespace std;
bool debug;
const int inf = 1e9 + 5;
const int nax = 205;
namespace MinCost {
struct Edge {
  int w, c, v, rev;
  Edge(int _w, int _c, int _v, int _rev) : w(_w), c(_c), v(_v), rev(_rev) {}
};
int odl[nax], pot[nax], pop[nax], pop_kraw[nax];
int q[nax], qbeg, qend;
vector<Edge> v[nax];
bool bylo[nax];
queue<int> kolej;
void init(int n) {
  for (int i = 0; i <= n; ++i) v[i].clear();
}
void AddEdge(int a, int b, int cap, int cost) {
  v[a].push_back(Edge(b, cap, cost, int(v[b].size()) + (a == b)));
  v[b].push_back(Edge(a, 0, -cost, int(v[a].size() - 1)));
}
pair<int, int> MinCostMaxFlow(int s, int t, int n) {
  int flow = 0, cost = 0;
  while (true) {
    for (int i = 0; i <= n; ++i) {
      odl[i] = inf;
      bylo[i] = false;
    }
    bylo[s] = true;
    odl[s] = 0;
    kolej.push(s);
    while (!kolej.empty()) {
      int x = kolej.front();
      kolej.pop();
      bylo[x] = false;
      int dl = v[x].size();
      for (int i = 0; i <= (dl)-1; ++i)
        if (v[x][i].c > 0 &&
            odl[v[x][i].w] > odl[x] + pot[x] - pot[v[x][i].w] + v[x][i].v) {
          odl[v[x][i].w] = odl[x] + pot[x] - pot[v[x][i].w] + v[x][i].v;
          if (!bylo[v[x][i].w]) {
            kolej.push(v[x][i].w);
            bylo[v[x][i].w] = true;
          }
          pop[v[x][i].w] = x;
          pop_kraw[v[x][i].w] = i;
        }
    }
    if (odl[t] == inf) break;
    int x = t;
    int cap = inf;
    while (x != s) {
      cap = min(cap, v[pop[x]][pop_kraw[x]].c);
      x = pop[x];
    }
    flow += cap;
    x = t;
    while (x != s) {
      cost += v[pop[x]][pop_kraw[x]].v * cap;
      v[pop[x]][pop_kraw[x]].c -= cap;
      v[x][v[pop[x]][pop_kraw[x]].rev].c += cap;
      x = pop[x];
    }
  }
  return make_pair(flow, cost);
}
};  // namespace MinCost
using namespace MinCost;
char t[nax], s[nax];
int ile[nax];
int n, a;
int main(int argc, char* argv[]) {
  debug = argc > 1;
  scanf(" %s", t);
  int dlt = strlen(t);
  scanf("%d", &n);
  MinCost::init(n + 28);
  for (int i = 1; i <= n; ++i) {
    scanf(" %s %d", s, &a);
    MinCost::AddEdge(0, i, a, i);
    int dl = strlen(s);
    for (int j = 0; j <= (dl)-1; ++j) ++ile[s[j] - 'a'];
    for (int j = 0; j <= (26) - 1; ++j) {
      MinCost::AddEdge(i, n + j + 1, ile[j], 0);
      ile[j] = 0;
    }
  }
  for (int i = 0; i <= (dlt)-1; ++i) ++ile[t[i] - 'a'];
  for (int i = 0; i <= (26) - 1; ++i)
    MinCost::AddEdge(n + i + 1, n + 28, ile[i], 0);
  pair<int, int> x = MinCost::MinCostMaxFlow(0, n + 28, n + 28);
  if (x.first < dlt) x.second = -1;
  printf("%d\n", x.second);
  return 0;
}
