#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
const int inf = 0x3f3f3f3f;
int head[N], path[N], inq[N], dis[N];
int n, m;
int ans;
int l;
int Flow;
char s[109][109], str[109];
struct Edge {
  int s, e, cost, flow;
  int next;
};
Edge edge[N];
void add(int s, int e, int flow, int cost) {
  edge[l].s = s;
  edge[l].e = e;
  edge[l].cost = cost;
  edge[l].flow = flow;
  edge[l].next = head[s];
  head[s] = l++;
  edge[l].s = e;
  edge[l].e = s;
  edge[l].cost = -cost;
  edge[l].flow = 0;
  edge[l].next = head[e];
  head[e] = l++;
}
bool spfa(int ss, int ee) {
  memset(dis, inf, sizeof(dis));
  memset(inq, 0, sizeof(inq));
  memset(path, -1, sizeof(path));
  queue<int> q;
  dis[ss] = 0;
  q.push(ss);
  inq[ss] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inq[u] = 0;
    for (int i = head[u]; i + 1; i = edge[i].next) {
      int v = edge[i].e;
      if (edge[i].flow > 0 && dis[v] > dis[u] + edge[i].cost) {
        dis[v] = dis[u] + edge[i].cost;
        path[v] = i;
        if (inq[v] == 0) {
          inq[v] = 1;
          q.push(v);
        }
      }
    }
  }
  return dis[ee] != inf;
}
void mincostflow(int ss, int ee) {
  ans = 0;
  int minflow;
  Flow = 0;
  while (spfa(ss, ee)) {
    minflow = inf;
    for (int i = path[ee]; i + 1; i = path[edge[i].s]) {
      minflow = min(minflow, edge[i].flow);
    }
    for (int i = path[ee]; i + 1; i = path[edge[i].s]) {
      edge[i].flow -= minflow;
      edge[i ^ 1].flow += minflow;
    }
    ans += dis[ee] * minflow;
    Flow += minflow;
  }
}
int main() {
  int vis[30];
  int cnt[109][30];
  int len[109];
  int c[109];
  int t;
  while (~scanf("%s", str)) {
    memset(head, -1, sizeof(head));
    l = 0;
    memset(vis, 0, sizeof(vis));
    memset(cnt, 0, sizeof(cnt));
    len[0] = strlen(str);
    for (int i = 0; i < len[0]; i++) {
      vis[str[i] - 'a' + 1]++;
    }
    scanf("%d", &n);
    t = n + 28;
    for (int i = 1; i <= n; i++) {
      scanf("%s %d", s[i], &c[i]);
      len[i] = strlen(s[i]);
      for (int j = 0; j < len[i]; j++) {
        cnt[i][s[i][j] - 'a' + 1]++;
      }
    }
    for (int i = 1; i <= 26; i++) {
      if (vis[i] == 0) continue;
      add(0, i, vis[i], 0);
      for (int j = 1; j <= n; j++) {
        if (cnt[j][i]) {
          add(i, j + 26, cnt[j][i], j);
        }
      }
    }
    for (int i = 1; i <= n; i++) add(i + 26, t, c[i], 0);
    mincostflow(0, t);
    if (Flow != len[0])
      printf("-1\n");
    else
      printf("%d\n", ans);
  }
}
