#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const int inf = 1e9;
string S[maxn];
string T;
int w[maxn];
int num[26];
int c[26][maxn];
int n;
int s, t;
int visit[maxn];
int dis[maxn];
int pre[maxn];
int lst[maxn];
int flow[maxn];
int maxflow;
int mincost;
struct node {
  int u, v, flow, dis, nxt;
} edge[maxn * 2];
int tot;
int head[maxn];
void addedge(int u, int v, int flow, int dis) {
  edge[tot].u = u;
  edge[tot].v = v;
  edge[tot].flow = flow;
  edge[tot].dis = dis;
  edge[tot].nxt = head[u];
  head[u] = tot++;
  edge[tot].u = v;
  edge[tot].v = u;
  edge[tot].flow = 0;
  edge[tot].dis = -dis;
  edge[tot].nxt = head[v];
  head[v] = tot++;
}
bool spfa(int s, int t) {
  for (int i = 0; i < maxn; i++) dis[i] = inf, flow[i] = inf, visit[i] = 0;
  queue<int> q;
  q.push(s);
  visit[s] = 1;
  dis[s] = 0;
  pre[t] = -1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    visit[u] = 0;
    for (int i = head[u]; i != -1; i = edge[i].nxt) {
      if (edge[i].flow > 0 && dis[edge[i].v] > dis[u] + edge[i].dis) {
        dis[edge[i].v] = dis[u] + edge[i].dis;
        pre[edge[i].v] = u;
        lst[edge[i].v] = i;
        flow[edge[i].v] = min(flow[u], edge[i].flow);
        if (!visit[edge[i].v]) {
          visit[edge[i].v] = 1;
          q.push(edge[i].v);
        }
      }
    }
  }
  return pre[t] != -1;
}
void MCMF() {
  while (spfa(s, t)) {
    int u = t;
    maxflow += flow[t];
    mincost += flow[t] * dis[t];
    while (u != s) {
      edge[lst[u]].flow -= flow[t];
      edge[lst[u] ^ 1].flow += flow[t];
      u = pre[u];
    }
  }
}
int main() {
  memset(head, -1, sizeof(head));
  cin >> T;
  scanf("%d", &n);
  s = 0;
  t = 27 + n;
  for (int i = 1; i <= n; i++) cin >> S[i] >> w[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < S[i].length(); j++) c[S[i][j] - 'a'][i]++;
  }
  for (int i = 0; i < T.length(); i++) num[T[i] - 'a']++;
  for (int i = 1; i <= 26; i++) addedge(s, i, num[i - 1], 0);
  for (int i = 1; i <= 26; i++) {
    for (int j = 1; j <= n; j++) {
      addedge(i, 26 + j, c[i - 1][j], j);
    }
  }
  for (int i = 1; i <= n; i++) addedge(26 + i, t, w[i], 0);
  MCMF();
  if (maxflow != T.length()) return printf("-1"), 0;
  printf("%d\n", mincost);
}
