#include <bits/stdc++.h>
using namespace std;
function<void(void)> ____ = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
const int MAXN = 3333;
const int INF = 0x3f3f3f3f;
int n, l, vis[MAXN], pre[MAXN], preid[MAXN], flow[MAXN], dist[MAXN];
struct EDGE {
  int to, cap, fee, rev;
  EDGE() {}
  EDGE(int _to, int _cap, int _fee, int _rev) {
    to = _to;
    cap = _cap;
    fee = _fee;
    rev = _rev;
  }
};
vector<EDGE> G[MAXN];
void ADDEDGE(int u, int v, int cap, int fee) {
  G[u].emplace_back(EDGE(v, cap, fee, (int)G[v].size()));
  G[v].emplace_back(EDGE(u, 0, -fee, (int)G[u].size() - 1));
}
bool spfa() {
  memset(dist, 0x3f, sizeof(dist));
  dist[0] = 0;
  flow[0] = INF;
  memset(vis, 0, sizeof(vis));
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    vis[u] = 0;
    for (int i = 0; i < (int)G[u].size(); i++) {
      auto e = G[u][i];
      if (!e.cap or dist[e.to] <= dist[u] + e.fee) continue;
      dist[e.to] = dist[u] + e.fee;
      flow[e.to] = min(e.cap, flow[u]);
      pre[e.to] = u;
      preid[e.to] = i;
      if (!vis[e.to]) {
        vis[e.to] = 1;
        que.push(e.to);
      }
    }
  }
  return dist[MAXN - 1] != INF;
}
int mcmf() {
  int cost = 0;
  int tot = 0;
  while (spfa()) {
    int u = MAXN - 1;
    cost += dist[MAXN - 1] * flow[MAXN - 1];
    tot += flow[MAXN - 1];
    while (u != 0) {
      int p = pre[u], id = preid[u];
      G[p][id].cap -= flow[MAXN - 1];
      G[u][G[p][id].rev].cap += flow[MAXN - 1];
      u = pre[u];
    }
  }
  return tot == l ? cost : -1;
}
string s;
int main() {
  ____();
  cin >> s >> n;
  l = s.length();
  vector<int> alpha(26, 0);
  for (int i = 0; i < (int)s.length(); i++) alpha[s[i] - 'a']++;
  for (int i = 0; i < 26; i++)
    if (alpha[i]) ADDEDGE(i + n + 1, MAXN - 1, alpha[i], 0);
  for (int i = 1; i <= n; i++) {
    fill(alpha.begin(), alpha.end(), 0);
    int lim;
    cin >> s >> lim;
    for (int j = 0; j < (int)s.length(); j++) alpha[s[j] - 'a']++;
    for (int j = 0; j < 26; j++)
      if (alpha[j]) ADDEDGE(i, j + 1 + n, alpha[j], 0);
    ADDEDGE(0, i, lim, i);
  }
  cout << mcmf() << endl;
  return 0;
}
