#include <bits/stdc++.h>
using namespace std;
const int MAXM = 100100;
const int MAXN = 500;
const int INF = (1 << 30);
char s[100100];
struct Edge {
  int next, from, to, cap, cost;
};
struct MCMF {
  Edge edge[MAXM];
  int head[MAXN], countedge;
  void Init(int N) {
    this->N = N;
    memset(head, -1, sizeof(head));
    countedge = 0;
  }
  int N;
  int inq[MAXN], dis[MAXN], pre[MAXN], ad[MAXN];
  void AddEdge(const int& start, const int& end, const int& cap,
               const int& cost) {
    edge[countedge].to = end;
    edge[countedge].from = start;
    edge[countedge].next = head[start];
    edge[countedge].cap = cap;
    edge[countedge].cost = cost;
    head[start] = countedge++;
    edge[countedge].to = start;
    edge[countedge].from = end;
    edge[countedge].next = head[end];
    edge[countedge].cap = 0;
    edge[countedge].cost = -cost;
    head[end] = countedge++;
  }
  bool BF(int s, int t, int& flow, int& cost) {
    int i;
    for (i = 0; i < N; i++) dis[i] = INF;
    memset(inq, 0, sizeof(inq));
    dis[s] = 0;
    inq[s] = 1;
    pre[s] = -1;
    ad[s] = INF;
    queue<int> que;
    que.push(s);
    int u, v, temp;
    while (!que.empty()) {
      u = que.front();
      que.pop();
      inq[u] = 0;
      for (temp = head[u]; temp != -1; temp = edge[temp].next) {
        v = edge[temp].to;
        if (edge[temp].cap && dis[v] > dis[u] + edge[temp].cost) {
          dis[v] = dis[u] + edge[temp].cost;
          pre[v] = temp;
          ad[v] = min(ad[u], edge[temp].cap);
          if (!inq[v]) {
            inq[v] = 1;
            que.push(v);
          }
        }
      }
    }
    if (dis[t] == INF) return false;
    flow += ad[t];
    cost += dis[t] * ad[t];
    u = t;
    while (u != s) {
      edge[pre[u]].cap -= ad[t];
      edge[pre[u] ^ 1].cap += ad[t];
      u = edge[pre[u]].from;
    }
    return true;
  }
  pair<int, int> MinC(int s, int t) {
    pair<int, int> ret;
    while (BF(s, t, ret.first, ret.second))
      ;
    return ret;
  }
} f;
int cc[30];
int main() {
  scanf("%s", s);
  int limit = strlen(s);
  int n;
  scanf("%d", &n);
  f.Init(n + 26 + 2);
  int ss = 0, tt = n + 26 + 1;
  for (int i = 0; s[i]; i++) {
    cc[s[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    f.AddEdge(i + 1 + n, tt, cc[i], 0);
  }
  for (int i = 0; i < n; i++) {
    scanf("%s", &s);
    memset(cc, 0, sizeof(cc));
    for (int j = 0; s[j]; j++) {
      cc[s[j] - 'a']++;
    }
    for (int j = 0; j < 26; j++) {
      f.AddEdge(i + 1, j + 1 + n, cc[j], i + 1);
    }
    int x;
    scanf("%d", &x);
    f.AddEdge(ss, i + 1, x, 0);
  }
  pair<int, int> ans = f.MinC(ss, tt);
  if (ans.first < limit) ans.second = -1;
  printf("%d\n", ans.second);
  return 0;
}
