#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > AdjList[3030];
vector<int> dist;
int f[3030][3030];
int parent[3030], n;
bool dks(int source, int sink) {
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  pq.push(pair<int, int>(0, source));
  memset(parent, -1, sizeof parent);
  parent[source] = source;
  dist.assign(3010, 123456789);
  dist[source] = 0;
  while (!pq.empty()) {
    int u = pq.top().second;
    pq.pop();
    for (int i = 0; i < (int)AdjList[u].size(); i++) {
      pair<int, int> v = AdjList[u][i];
      if (f[u][v.first] > 0 && dist[u] + v.second < dist[v.first]) {
        dist[v.first] = dist[u] + v.second;
        parent[v.first] = u;
        pq.push(pair<int, int>(dist[v.first], v.first));
      }
    }
  }
  return parent[sink] != -1;
}
pair<int, int> MaxFlow(int source, int sink) {
  int cost = 0;
  int flow = 0;
  while (dks(source, sink)) {
    int garg = 123456789;
    int v = sink;
    while (v != source) {
      garg = min(garg, f[parent[v]][v]);
      v = parent[v];
    }
    cost += garg * dist[sink];
    flow += garg;
    v = sink;
    while (v != source) {
      f[parent[v]][v] -= garg;
      f[v][parent[v]] += garg;
      v = parent[v];
    }
  }
  return pair<int, int>(flow, cost);
}
int main() {
  int a;
  map<int, int>::iterator it;
  string s1, s2;
  cin >> s1;
  for (int i = 0; i < (int)s1.size(); i++) {
    AdjList[i + 1].push_back(pair<int, int>(3000, 0));
    AdjList[3000].push_back(pair<int, int>(i + 1, 0));
    f[i + 1][3000] = 1;
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    map<int, int> mp;
    cin >> s2 >> a;
    for (int j = 0; j < (int)s2.size(); j++) {
      mp[s2[j] + 100]++;
    }
    for (it = mp.begin(); it != mp.end(); ++it) {
      for (int j = 0; j < (int)s1.size(); j++) {
        if ((int)s1[j] + 100 == it->first) {
          AdjList[it->first + 26 * i].push_back(pair<int, int>(j + 1, i + 1));
          AdjList[j + 1].push_back(
              pair<int, int>(it->first + 26 * i, -(i + 1)));
          f[it->first + 26 * i][j + 1] = 1;
        }
      }
      AdjList[i + 2800].push_back(pair<int, int>(it->first + 26 * i, 0));
      AdjList[it->first + 26 * i].push_back(pair<int, int>(i + 2800, 0));
      f[i + 2800][it->first + 26 * i] = it->second;
    }
    AdjList[0].push_back(pair<int, int>(i + 2800, 0));
    AdjList[i + 2800].push_back(pair<int, int>(0, 0));
    f[0][i + 2800] = a;
  }
  pair<int, int> res = MaxFlow(0, 3000);
  if (res.first == (int)s1.size())
    printf("%d\n", res.second);
  else
    printf("-1\n");
}
