#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
const int INF = 1e9 + 7;
namespace Dinic {
const int maxv = 205;
const int maxe = 5005;
int tote = 0, totv = 0, s, t;
int head[maxv], dis[maxv], fv[maxv], fe[maxv], inq[maxv], h[maxv];
int nxt[maxe], to[maxe], cap[maxe], cost[maxe];
inline int newNode() { return totv++; }
inline void init() {
  memset(head, -1, sizeof(head));
  tote = totv = 0;
  return;
}
inline void add(int u, int v, int w, int c) {
  nxt[tote] = head[u];
  to[tote] = v;
  cap[tote] = w;
  cost[tote] = c;
  head[u] = tote++;
  return;
}
inline void addEdge(int u, int v, int w, int c) {
  add(u, v, w, c);
  add(v, u, 0, -c);
  return;
}
inline void spfa(int s) {
  for (int i = (0); i < (totv); ++i) dis[i] = INF;
  dis[s] = 0;
  inq[s] = 0;
  queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    inq[u] = false;
    for (int i = head[u]; ~i; i = nxt[i]) {
      if (!cap[i]) continue;
      int v = to[i], w = cost[i];
      if (dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        if (!inq[v]) {
          que.push(v);
          inq[v] = true;
        }
        fv[v] = u;
        fe[v] = i;
      }
    }
  }
  return;
}
inline void dijkstra(int s) {
  for (int i = (0); i < (totv); ++i) dis[i] = INF;
  dis[s] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      que;
  que.push(make_pair(dis[s], s));
  while (!que.empty()) {
    int u = que.top().second, d = que.top().first;
    que.pop();
    if (dis[u] != d) continue;
    for (int i = head[u]; ~i; i = nxt[i]) {
      if (!cap[i]) continue;
      int v = to[i], w = cost[i];
      if (dis[v] > dis[u] + w + h[u] - h[v]) {
        dis[v] = dis[u] + w + h[u] - h[v];
        que.push(make_pair(dis[v], v));
        fv[v] = u;
        fe[v] = i;
      }
    }
  }
  return;
}
inline int minCostFlow(int f) {
  int ret = 0;
  memset(h, 0, sizeof(h));
  spfa(s);
  while (f > 0) {
    if (dis[t] == INF) return -1;
    int flow = f;
    for (int u = t; u != s; u = fv[u]) flow = min(flow, cap[fe[u]]);
    for (int u = t; u != s; u = fv[u]) {
      cap[fe[u]] -= flow;
      cap[fe[u] ^ 1] += flow;
    }
    for (int i = (0); i < (totv); ++i) {
      h[i] += dis[i];
    }
    ret += h[t] * flow;
    f -= flow;
    dijkstra(s);
  }
  return ret;
}
}  // namespace Dinic
int m;
int a[maxn], c[maxn], alp[30];
int cnt[maxn][30];
char s[maxn][maxn];
int main() {
  scanf("%s", s[0]);
  a[0] = strlen(s[0]);
  scanf("%d", &m);
  for (int i = (1); i <= (m); ++i) {
    scanf("%s%d", s[i], c + i);
    a[i] = strlen(s[i]);
  }
  for (int i = (0); i <= (m); ++i)
    for (int j = (0); j < (a[i]); ++j) ++cnt[i][s[i][j] - 'a'];
  Dinic::init();
  Dinic::s = Dinic::newNode();
  Dinic::t = Dinic::newNode();
  for (int i = (0); i < (26); ++i)
    if (cnt[0][i]) {
      alp[i] = Dinic::newNode();
      Dinic::addEdge(alp[i], Dinic::t, cnt[0][i], 0);
    }
  for (int i = (1); i <= (m); ++i) {
    int u = Dinic::newNode();
    Dinic::addEdge(Dinic::s, u, c[i], i);
    for (int j = (0); j <= (26); ++j)
      if (cnt[i][j]) {
        Dinic::addEdge(u, alp[j], cnt[i][j], 0);
      }
  }
  printf("%d\n", Dinic::minCostFlow(a[0]));
  return 0;
}
