#include <bits/stdc++.h>
using namespace std;
int min(int x, int y) { return x < y ? x : y; }
int max(int x, int y) { return x > y ? x : y; }
const int N = 100005;
const int M = 200001;
struct node {
  int x, y, next;
  int c, w, re;
};
node s[M];
int h[N], pre[N], dis[N], vis[N], E;
void clear() {
  E = 1;
  memset(h, -1, sizeof(h));
}
void insert(int x, int y, int w, int c) {
  s[E].x = x;
  s[E].y = y;
  s[E].w = w;
  s[E].c = c;
  s[E].re = E + 1;
  s[E].next = h[x];
  h[x] = E++;
  s[E].x = y;
  s[E].y = x;
  s[E].w = 0;
  s[E].c = -c;
  s[E].re = E - 1;
  s[E].next = h[y];
  h[y] = E++;
}
queue<int> q;
bool spfa(int st, int en) {
  int x, y, i;
  memset(pre, 0, sizeof(pre));
  memset(vis, 0, sizeof(vis));
  for (i = 0; i < N; i++) dis[i] = 2000000007;
  dis[st] = 0;
  q.push(st);
  while (!q.empty()) {
    x = q.front();
    q.pop();
    vis[x] = 0;
    for (i = h[x]; i != -1; i = s[i].next) {
      y = s[i].y;
      if (s[i].w > 0 && dis[x] + s[i].c < dis[y]) {
        dis[y] = dis[x] + s[i].c;
        pre[y] = i;
        if (!vis[y]) {
          vis[y] = 1;
          q.push(y);
        }
      }
    }
  }
  if (dis[en] == 2000000007) return 0;
  return 1;
}
int mcmf(int st, int en, int m) {
  int ans = 0, sum = 0;
  int i, Min = 2000000007;
  while (spfa(st, en)) {
    ans += dis[en];
    for (i = pre[en]; i; i = pre[s[i].x]) Min = min(Min, s[i].w);
    for (i = pre[en]; i; i = pre[s[i].x]) {
      s[i].w -= Min;
      s[s[i].re].w += Min;
    }
    sum += Min;
  }
  if (sum != m) ans = -1;
  return ans;
}
char str[105];
int mark[26];
int main() {
  int i, j, k;
  int n, m, tt;
  int x, y;
  while (scanf("%s", str) != EOF) {
    clear();
    scanf("%d", &n);
    m = strlen(str);
    memset(mark, 0, sizeof(mark));
    for (i = 0; i < m; i++) mark[str[i] - 'a']++;
    int st = 0, en = n + 26 + 1;
    for (i = 0; i < 26; i++)
      if (mark[i]) insert(n + i + 1, en, mark[i], 0);
    for (i = 1; i <= n; i++) {
      scanf("%s%d", str, &x);
      insert(st, i, x, 0);
      k = strlen(str);
      for (j = 0; j < k; j++) insert(i, n + str[j] - 'a' + 1, 1, i);
    }
    printf("%d\n", mcmf(st, en, m));
  }
  return 0;
}
