#include <bits/stdc++.h>
using namespace std;
struct EDGE {
  int v, cap, cost, next, re;
} edge[1111111];
int n, m, ans, flow, src, des;
int e, head[11111];
int que[11111], pre[11111], dis[11111];
bool vis[11111];
void init() {
  e = ans = flow = 0;
  memset(head, -1, sizeof(head));
}
void add(int u, int v, int cap, int cost) {
  edge[e].v = v;
  edge[e].cap = cap;
  edge[e].cost = cost;
  edge[e].next = head[u];
  edge[e].re = e + 1;
  head[u] = e++;
  edge[e].v = u;
  edge[e].cap = 0;
  edge[e].cost = -cost;
  edge[e].next = head[v];
  edge[e].re = e - 1;
  head[v] = e++;
}
bool spfa() {
  int i, h = 0, t = 1;
  for (i = 0; i <= n; i++) {
    dis[i] = 1000000007;
    vis[i] = false;
  }
  dis[src] = 0;
  que[0] = src;
  vis[src] = true;
  while (t != h) {
    int u = que[h++];
    h %= n;
    vis[u] = false;
    for (i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].v;
      if (edge[i].cap && dis[v] > dis[u] + edge[i].cost) {
        dis[v] = dis[u] + edge[i].cost;
        pre[v] = i;
        if (!vis[v]) {
          vis[v] = true;
          que[t++] = v;
          t %= n;
        }
      }
    }
  }
  if (dis[des] == 1000000007) return false;
  return true;
}
void end() {
  int u, p, mi = 1000000007;
  for (u = des; u != src; u = edge[edge[p].re].v) {
    p = pre[u];
    mi = min(mi, edge[p].cap);
  }
  for (u = des; u != src; u = edge[edge[p].re].v) {
    p = pre[u];
    edge[p].cap -= mi;
    edge[edge[p].re].cap += mi;
    ans += mi * edge[p].cost;
  }
  flow += mi;
}
char str[111], req[11111];
int nt;
int tt[11111];
int ss;
void build() {
  scanf("%s", req);
  scanf("%d", &nt);
  ss = strlen(req);
  for (int i = 0; i < ss; i++) tt[req[i] - 'a']++;
  src = 1;
  n = nt + 28;
  des = n;
  int v[33];
  int xy;
  for (int i = 0; i < nt; i++) {
    scanf("%s%d", str, &xy);
    int len = strlen(str);
    memset(v, 0, sizeof(v));
    int now = 2 + i;
    add(src, now, xy, 0);
    for (int j = 0; j < len; j++) v[str[j] - 'a']++;
    for (int j = 0; j < 26; j++)
      if (v[j]) add(now, nt + 2 + j, v[j], i + 1);
  }
  for (int i = 0; i < 26; i++) add(nt + 2 + i, des, tt[i], 0);
}
void MCMF() {
  init();
  build();
  while (spfa()) end();
  if (flow != ss)
    printf("-1\n");
  else
    printf("%d\n", ans);
}
int main() {
  MCMF();
  return 0;
}
