#include <bits/stdc++.h>
using namespace std;
struct flux {
  long long flux, capacitate, cost;
};
string t, s[105];
long long n, m, a[105], d[305];
flux M[305][305];
queue<long long> Q;
long long Viz[305], answer;
long long dj;
long long DJ[305];
set<pair<long long, long long> > S;
long long prevv[305];
bool DFS(vector<pair<long long, long long> > &Path) {
  Path.clear();
  for (long long i = 1; i <= n + m + 1; i++) DJ[i] = (long long)1e9;
  memset(prevv, -1, sizeof(prevv));
  DJ[0] = 0;
  S.insert({d[0], 0});
  while (!S.empty()) {
    long long dist = S.begin()->first;
    long long nod = S.begin()->second;
    S.erase(S.begin());
    if (nod == n + m + 1) continue;
    for (long long i = 1; i <= n + m + 1; i++) {
      if (M[nod][i].capacitate == 0 && M[nod][i].cost == 0 &&
          M[nod][i].flux == 0)
        continue;
      if (M[nod][i].flux == M[nod][i].capacitate) continue;
      if (dist + M[nod][i].cost < DJ[i]) {
        if (S.find({DJ[i], i}) != S.end()) S.erase(S.find({DJ[i], i}));
        DJ[i] = dist + M[nod][i].cost;
        prevv[i] = nod;
        S.insert({DJ[i], i});
      }
    }
  }
  if (prevv[n + m + 1] == -1) return 0;
  long long act = n + m + 1;
  while (prevv[act] != -1) {
    Path.push_back({prevv[act], act});
    act = prevv[act];
  }
  reverse(Path.begin(), Path.end());
  return 1;
}
int F[30];
int main() {
  cin >> t;
  m = 27;
  for (auto i : t) F[i - 'a']++;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> s[i] >> a[i];
  for (long long i = 1; i <= n; i++) {
    flux f = {0, a[i], i};
    M[0][i] = f;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < m; j++) {
      if (F[j] == 0) continue;
      int nr = 0;
      for (auto k : s[i])
        if (k == j + 'a') nr++;
      flux f = {0, nr, 0};
      M[i][n + j + 1] = f;
      f = {0, 0, 0};
      M[n + j + 1][i] = f;
    }
  }
  for (long long i = 0; i < m; i++) {
    flux f = {0, F[i], 0};
    M[n + 1 + i][n + m + 1] = f;
  }
  vector<pair<long long, long long> > Path;
  long long flux_maxim = 0;
  while (DFS(Path)) {
    long long minim = 1e9;
    long long cost = 0;
    for (long long i = 0; i < Path.size(); i++) {
      long long x = Path[i].first;
      long long y = Path[i].second;
      cost += M[x][y].cost;
      if (M[x][y].capacitate - M[x][y].flux < minim)
        minim = M[x][y].capacitate - M[x][y].flux;
    }
    for (long long i = 0; i < Path.size(); i++) {
      long long x = Path[i].first;
      long long y = Path[i].second;
      M[x][y].flux += minim;
      M[y][x].flux -= minim;
    }
    flux_maxim += minim;
    answer += cost * minim;
  }
  if (flux_maxim != t.size())
    cout << -1 << endl;
  else
    cout << answer << endl;
  return 0;
}
