#include <bits/stdc++.h>
using namespace std;
string t, s[102];
long long number_it_can_send[102];
long long INF = 1e10;
vector<long long> adj[130];
long long capacity[130][130], cost[130][130];
long long d[130], parent[130];
vector<pair<long long, long long> > edges;
void bellman_ford(int s, int t, long long n) {
  memset(parent, -1, sizeof(parent));
  for (int i = 0; i <= 129; i++) d[i] = INF;
  d[0] = 0;
  long long m = edges.size();
  for (int i = 0; i < 125; i++) {
    for (int j = 0; j < m; j++) {
      if (d[edges[j].first] < INF) {
        if (d[edges[j].second] >
            d[edges[j].first] + cost[edges[j].first][edges[j].second]) {
          if (capacity[edges[j].first][edges[j].second] <= 0) continue;
          parent[edges[j].second] = edges[j].first;
          d[edges[j].second] =
              d[edges[j].first] + cost[edges[j].first][edges[j].second];
        }
      }
    }
  }
}
long long min_cost_max_flow(int s, int t, long long K, long long n) {
  long long flow = 0, cs = 0;
  while (true) {
    bellman_ford(s, t, n);
    if (d[t] >= INF) break;
    long long new_flow = INF;
    int cur = t;
    while (cur != s) {
      new_flow = min(new_flow, capacity[parent[cur]][cur]);
      cur = parent[cur];
    }
    flow += new_flow;
    cs += new_flow * d[t];
    cur = t;
    while (cur != s) {
      capacity[parent[cur]][cur] -= new_flow;
      capacity[cur][parent[cur]] += new_flow;
      cur = parent[cur];
    }
  }
  if (flow < K)
    return INF;
  else
    return cs;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> t;
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i] >> number_it_can_send[i];
  for (int i = 1; i <= n; i++) {
    capacity[0][i] = number_it_can_send[i];
    adj[0].push_back(i);
    adj[i].push_back(0);
    edges.push_back({0, i});
    edges.push_back({i, 0});
  }
  for (int i = 1; i <= n; i++) {
    int cnt[26] = {0};
    for (int j = 0; j < s[i].size(); j++) {
      cnt[s[i][j] - 'a']++;
    }
    for (int j = 1; j <= 26; j++) {
      adj[i].push_back(100 + j);
      adj[100 + j].push_back(i);
      capacity[i][100 + j] = cnt[j - 1];
      cost[i][100 + j] = i;
      cost[100 + j][i] = -i;
      edges.push_back({i, 100 + j});
      edges.push_back({100 + j, i});
    }
  }
  int chahiye[26] = {0};
  for (int i = 0; i < t.size(); i++) {
    chahiye[t[i] - 'a']++;
  }
  for (int i = 1; i <= 26; i++) {
    adj[100 + i].push_back(129);
    adj[129].push_back(100 + i);
    edges.push_back({100 + i, 129});
    edges.push_back({129, 100 + i});
    capacity[100 + i][129] = chahiye[i - 1];
    cost[100 + i][129] = cost[129][100 + i] = 0;
  }
  long long ans = min_cost_max_flow(0, 129, t.size(), n);
  if (ans == INF)
    cout << "-1" << endl;
  else
    cout << ans << endl;
}
