#include <bits/stdc++.h>
using namespace std;
const int maxe = 100000;
const int maxn = 205;
const int INF = 0x3f3f3f3f;
int ans;
struct Edge {
  int u, v, flow, cap, cost;
  int next;
  Edge(int u = 0, int v = 0, int flow = 0, int cap = 0, int cost = 0,
       int next = 0)
      : u(u), v(v), flow(flow), cap(cap), cost(cost), next(next) {}
};
struct MCMF {
  Edge edges[maxe];
  int head[maxn], cnt;
  int d[maxn];
  bool inq[maxn];
  int pa[maxn];
  int res[maxn];
  void init() {
    memset(head, -1, sizeof(head));
    cnt = 0;
  }
  void addedge(int u, int v, int cap, int xx, int cost, int yy) {
    edges[cnt] = Edge(u, v, 0, cap, cost, head[u]);
    head[u] = cnt++;
    edges[cnt] = Edge(v, u, 0, 0, -cost, head[v]);
    head[v] = cnt++;
  }
  bool SPFA(int s, int t, int& flow, int& cost) {
    memset(d, 0x3f, sizeof(d));
    memset(inq, 0, sizeof(inq));
    queue<int> Q;
    Q.push(s);
    inq[s] = true;
    d[s] = 0;
    res[s] = INF;
    res[t] = 0;
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      inq[u] = false;
      for (int i = head[u]; i != -1; i = edges[i].next) {
        Edge& e = edges[i];
        if (e.cap > e.flow && d[e.v] > d[u] + e.cost) {
          d[e.v] = d[u] + e.cost;
          pa[e.v] = i;
          res[e.v] = min(res[u], e.cap - e.flow);
          if (!inq[e.v]) {
            Q.push(e.v);
            inq[e.v] = true;
          }
        }
      }
    }
    if (res[t] == 0) return false;
    flow += res[t];
    cost += res[t] * d[t];
    for (int i = t; i != s; i = edges[pa[i]].u) {
      edges[pa[i]].flow += res[t];
      edges[pa[i] ^ 1].flow -= res[t];
    }
    return true;
  }
  int MinCost(int s, int t) {
    int flow = 0, cost = 0;
    while (SPFA(s, t, flow, cost)) {
    }
    ans = flow;
    return cost;
  }
} solver;
int lim[109];
string mn;
int n;
int run[109][28];
int req[28];
int main() {
  cin >> mn;
  cin >> n;
  int i;
  solver.init();
  int sum = 0;
  for (i = (0); i < (int)(mn.size()); ++i) {
    int x = mn[i] - 'a';
    req[x]++;
  }
  for (i = (0); i < (int)(26); ++i) {
    sum += req[i];
    if (req[i] == 0) continue;
    solver.addedge(0, i + 1, req[i], 0, 0, 0);
  }
  for (i = (0); i < (int)(n); ++i) {
    string b;
    cin >> b >> lim[i];
    int j;
    int nn = b.size();
    lim[i] = min(lim[i], nn);
    for (j = (0); j < (int)(b.size()); ++j) {
      int x = b[j] - 'a';
      run[i][x]++;
    }
  }
  for (i = (0); i < (int)(26); ++i) {
    if (req[i] == 0) continue;
    int j;
    for (j = (0); j < (int)(n); ++j) {
      if (run[j][i] == 0) continue;
      int en = j * 26 + i + 1 + n + 26;
      solver.addedge(i + 1, 27 + j, run[j][i], 0, j + 1, 0);
    }
  }
  int j;
  int sink = n + 26 + 1;
  for (i = (1); i < (int)(n + 1); ++i) {
    solver.addedge(26 + i, sink, lim[i - 1], 0, 0, 0);
  }
  int xx = solver.MinCost(0, sink);
  if (ans != sum) xx = -1;
  cout << xx << endl;
  return 0;
}
