#include <bits/stdc++.h>
using namespace std;
const int max_n = 200;
const int inf = INT_MAX;
struct Edge {
  int to, cap, cost, rev;
};
vector<Edge> G[max_n];
void Add(int from, int to, int cap, int cost) {
  G[from].push_back((Edge){to, cap, cost, (int)G[to].size()});
  G[to].push_back((Edge){from, 0, -cost, (int)G[from].size() - 1});
}
int PreV[max_n], PreE[max_n];
int n, s, t;
int Dis[max_n], cnt[max_n][26] = {{0}};
string Tar;
int min_cost_flow(int f) {
  int res = 0;
  while (f > 0) {
    fill(Dis, Dis + max_n, inf);
    Dis[s] = 0;
    bool update = true;
    while (update) {
      update = false;
      for (int i = 0; i <= n + 27; i++) {
        if (Dis[i] == inf) continue;
        for (int j = 0; j < G[i].size(); j++) {
          Edge &e = G[i][j];
          if (e.cap > 0 && Dis[e.to] > Dis[i] + e.cost) {
            Dis[e.to] = Dis[i] + e.cost;
            update = true;
            PreV[e.to] = i;
            PreE[e.to] = j;
          }
        }
      }
    }
    if (Dis[t] == inf) return -1;
    int d = f;
    for (int v = t; v != s; v = PreV[v]) {
      d = min(d, G[PreV[v]][PreE[v]].cap);
    }
    f -= d;
    res += d * Dis[t];
    for (int v = t; v != s; v = PreV[v]) {
      Edge &e = G[PreV[v]][PreE[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}
int main() {
  cin >> Tar >> n;
  s = 0;
  t = n + 27;
  int Source[26] = {0};
  for (char i : Tar) {
    Source[i - 'a']++;
  }
  for (int i = 1; i <= n; i++) {
    string tmp;
    int num;
    cin >> tmp >> num;
    for (char c : tmp) {
      cnt[i][c - 'a']++;
    }
    Add(i, t, num, 0);
  }
  for (int i = 1; i <= 26; i++) {
    Add(s, n + i, Source[i - 1], 0);
    for (int j = 1; j <= n; j++) {
      Add(n + i, j, cnt[j][i - 1], j);
    }
  }
  cout << min_cost_flow(Tar.size());
  return 0;
}
