#include <bits/stdc++.h>
using namespace std;
template <typename T>
using vc = vector<T>;
using pii = pair<long long, long long>;
struct mcFlow {
  struct Edge {
    long long c;
    long long first;
    long long to, rev;
    Edge(long long _to, long long _c, long long _f, long long _rev)
        : c(_c), first(_f), to(_to), rev(_rev) {}
  };
  const long long INFCOST = numeric_limits<long long>::max() / 2;
  const long long INFFLOW = numeric_limits<long long>::max() / 2;
  long long N, S, T;
  vector<vector<Edge> > G;
  mcFlow(long long _N, long long _S, long long _T)
      : N(_N), S(_S), T(_T), G(_N) {}
  void add_edge(long long a, long long b, long long cost, long long cap) {
    if (a == b) {
      return;
    }
    assert(a >= 0 && a < N && b >= 0 && b < N);
    G[a].emplace_back(b, cost, cap, G[b].size());
    G[b].emplace_back(a, -cost, 0, G[a].size() - 1);
  }
  pair<long long, long long> minCostFlow() {
    vector<long long> phi(N, 0);
    vector<long long> dist(N);
    vector<long long> state(N);
    vector<Edge *> from(N, 0);
    queue<long long> q;
    long long retCost = 0;
    long long retFlow = 0;
    do {
      fill(dist.begin(), dist.end(), INFCOST);
      fill(state.begin(), state.end(), 0);
      fill(from.begin(), from.end(), (Edge *)0);
      dist[S] = 0;
      state[S] = 1;
      q.push(S);
      while (!q.empty()) {
        long long cur;
        cur = q.front();
        q.pop();
        state[cur] = 2;
        for (Edge &e : G[cur]) {
          if (e.first == 0) continue;
          long long newDist = dist[cur] + phi[cur] - phi[e.to] + e.c;
          if (newDist < dist[e.to]) {
            dist[e.to] = newDist;
            from[e.to] = &e;
            if (state[e.to] != 1) q.push(e.to);
            state[e.to] = 1;
          }
        }
      }
      if (from[T] == 0) break;
      long long augment = INFFLOW;
      for (Edge *e = from[T]; e; e = from[G[e->to][e->rev].to]) {
        augment = min(augment, e->first);
      }
      for (Edge *e = from[T]; e; e = from[G[e->to][e->rev].to]) {
        retCost += e->c * augment;
        e->first -= augment;
        G[e->to][e->rev].first += augment;
      }
      retFlow += augment;
      for (long long i = 0; i < N; ++i) {
        phi[i] += dist[i];
      }
    } while (from[T]);
    return make_pair(retFlow, retCost);
  }
  long long getFlow(Edge const &e) { return G[e.to][e.rev].first; }
};
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string t;
  cin >> t;
  long long n;
  cin >> n;
  vc<string> a(n + 1);
  vc<long long> cost(n + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    cin >> cost[i];
  }
  a[0] = t;
  vc<vc<long long> > anz(n + 1, vc<long long>(26));
  for (long long i = 0; i < n + 1; i++) {
    for (long long j = 0; j < a[i].size(); j++) {
      anz[i][a[i][j] - 'a']++;
    }
  }
  mcFlow first(2 + 26 + n, 26 + n, 26 + n + 1);
  for (long long i = 0; i < 26; i++) {
    first.add_edge(26 + n, i, 0, anz[0][i]);
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 0; j < 26; j++) {
      first.add_edge(j, 26 + i - 1, i, anz[i][j]);
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    first.add_edge(26 + i - 1, 26 + n + 1, 0, cost[i]);
  }
  auto res = first.minCostFlow();
  if (res.first != t.size())
    cout << "-1\n";
  else
    cout << res.second << "\n";
}
