#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
struct Edge {
  int from, to, capacity, cost;
  Edge(int v, int u, int C, int val) {
    from = v;
    to = u;
    capacity = C;
    cost = val;
  }
};
vector<vector<int>> g, capacity, cost;
void SPFA(int n, int Start, vector<int> &d, vector<int> &p) {
  vector<bool> used(n + 1, 0);
  d.assign(n + 1, INF);
  p.assign(n + 1, -1);
  used[Start] = 1;
  d[Start] = 0;
  queue<int> fb;
  fb.push(Start);
  while (!fb.empty()) {
    int v = fb.front();
    fb.pop();
    used[v] = 0;
    for (int &i : g[v]) {
      if (capacity[v][i] <= 0) continue;
      if (d[i] <= d[v] + cost[v][i]) continue;
      d[i] = d[v] + cost[v][i];
      p[i] = v;
      if (!used[i]) {
        used[i] = 1;
        fb.push(i);
      }
    }
  }
}
int min_cost_max_flow(int N, vector<Edge> edges, int s, int t, int F) {
  g.assign(N + 1, vector<int>());
  cost.assign(N + 1, vector<int>(N + 1, 0));
  capacity.assign(N + 1, vector<int>(N + 1, 0));
  for (Edge &i : edges) {
    g[i.from].push_back(i.to);
    g[i.to].push_back(i.from);
    capacity[i.from][i.to] = i.capacity;
    cost[i.from][i.to] = i.cost;
    cost[i.to][i.from] = -i.cost;
  }
  int cost = 0, flow = 0;
  vector<int> d, p;
  while (flow < F) {
    SPFA(N, s, d, p);
    if (d[t] == INF) break;
    int delta = F - flow;
    int cur = t;
    while (cur != s) {
      delta = min(delta, capacity[p[cur]][cur]);
      cur = p[cur];
    }
    flow += delta;
    cost += delta * d[t];
    cur = t;
    while (cur != s) {
      capacity[p[cur]][cur] -= delta;
      capacity[cur][p[cur]] += delta;
      cur = p[cur];
    }
  }
  if (flow < F) return -1;
  return cost;
}
void bober() {
  vector<Edge> edges;
  string s, t;
  int n;
  cin >> s;
  int numV = 2;
  vector<int> num_of_char(26, 0);
  vector<int> num(26, -1);
  for (char &i : s) num_of_char[i - 'a']++;
  for (int i = 0; i <= 25; i++)
    if (num_of_char[i])
      num[i] = ++numV, edges.push_back(Edge(numV, 2, num_of_char[i], 0));
  cin >> n;
  for (int cc, i = 1; i <= n; i++) {
    ++numV;
    cin >> t >> cc;
    vector<int> cnt(26, 0);
    for (char &j : t) cnt[j - 'a']++;
    for (int j = 0; j <= 25; j++) {
      if (!cnt[j] || !num_of_char[j]) continue;
      edges.push_back(Edge(numV, num[j], min(num_of_char[j], cnt[j]), i));
    }
    edges.push_back(Edge(1, numV, cc, 0));
  }
  cout << min_cost_max_flow(numV, edges, 1, 2, s.size());
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  q = 1;
  while (q--) {
    bober();
  }
  return 0;
}
