#include <bits/stdc++.h>
using namespace std;
clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& q) {
  in >> q.first >> q.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2>& q) {
  out << q.first << " " << q.second;
  return out;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2) {
  return {p1.first + p2.first, p1.second + p2.second};
}
template <typename T1, typename T2>
pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2) {
  return {p1.first - p2.first, p1.second - p2.second};
}
const long long N = 150;
struct MinCostFlow {
  struct Edge {
    long long f;
    long long c;
    long long u;
    Edge* nex;
    Edge* rev;
    Edge(long long _u, long long _c, long long _f, Edge* _nex)
        : f(_f), u(_u), c(_c), nex(_nex) {}
  };
  vector<Edge*> g;
  MinCostFlow(long long n) { g.resize(n); }
  void AddEdge(long long v, long long u, long long c, long long f) {
    g[v] = new Edge(u, c, f, g[v]);
    g[u] = new Edge(v, -c, 0, g[u]);
    g[v]->rev = g[u];
    g[u]->rev = g[v];
  }
  pair<long long, long long> Flow(long long src, long long sink, long long n) {
    long long flow = 0;
    long long cost = 0;
    while (true) {
      vector<long long> dis(n, (long long)(1e9));
      vector<Edge*> par(n);
      vector<bool> vis(n, false);
      vector<long long> mn(n, 0);
      queue<long long> q;
      q.push(src);
      dis[src] = 0;
      vis[src] = 1;
      mn[src] = (long long)(1e9);
      while (!q.empty()) {
        long long v = q.front();
        q.pop();
        vis[v] = 0;
        for (Edge* e = g[v]; e; e = e->nex) {
          if (e->f <= 0) continue;
          if (dis[e->u] > dis[v] + e->c) {
            dis[e->u] = dis[v] + e->c;
            mn[e->u] = min(mn[v], e->f);
            par[e->u] = e;
            if (!vis[e->u]) {
              vis[e->u] = 1;
              q.push(e->u);
            }
          }
        }
      }
      if (dis[sink] == (long long)(1e9)) break;
      long long curr = sink;
      long long ff = mn[sink];
      cost += ff * dis[sink];
      flow += ff;
      while (curr != src) {
        Edge* e = par[curr];
        e->f -= ff;
        e->rev->f += ff;
        curr = e->rev->u;
      }
    }
    return {flow, cost};
  }
} mcf(N);
void solve() {
  string t, s;
  cin >> s;
  long long cnt[26] = {0};
  long long sink = 0, curr = 1;
  for (long long i = 0; i < (long long)((s).size()); i++) cnt[s[i] - 'a']++;
  for (long long i = 0; i < 26; i++) {
    mcf.AddEdge(curr, sink, 0, cnt[i]), curr++;
  }
  long long n;
  cin >> n;
  long long a[n];
  long long ver[n];
  for (long long i = 0; i < n; i++) {
    cin >> t >> a[i];
    memset(cnt, 0, sizeof(cnt));
    for (long long j = 0; j < (long long)((t).size()); j++) cnt[t[j] - 'a']++;
    for (long long j = 0; j < 26; j++) mcf.AddEdge(curr, j + 1, i + 1, cnt[j]);
    ver[i] = curr;
    curr++;
  }
  for (long long i = 0; i < n; i++) {
    mcf.AddEdge(curr, ver[i], 0, a[i]);
  }
  pair<long long, long long> ans = mcf.Flow(curr, sink, curr + 1);
  if (ans.first == (long long)((s).size())) {
    cout << ans.second << '\n';
  } else
    cout << -1 << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  start = clock();
  cout << fixed << setprecision(7);
  for (long long i = 1; i <= t; i++) {
    solve();
  }
  double time_taken = double(clock() - start) / double(CLOCKS_PER_SEC);
  cerr << time_taken;
  return 0;
}
