#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
struct Edge {
  int src, dst;
  int cst;
  int cap;
  int rev;
  Edge() {}
  Edge(int src, int dst, int cst, int cap, int rev)
      : src(src), dst(dst), cst(cst), cap(cap), rev(rev) {}
};
bool operator<(const Edge a, const Edge b) { return a.cst > b.cst; }
void add_edge(vector<vector<Edge> > &G, int u, int v, int c, int l) {
  G[u].push_back(Edge(u, v, l, c, G[v].size()));
  G[v].push_back(Edge(v, u, -l, 0, (int)G[u].size() - 1));
}
pair<int, int> flow(vector<vector<Edge> > &G, int s, int t, int K = INF) {
  int n = G.size();
  int flow = 0;
  int cost = 0;
  while (1) {
    priority_queue<Edge> Q;
    vector<int> prev(n, -1), prev_num(n, -1);
    vector<int> length(n, INF);
    Q.push(Edge(-1, s, 0, 0, 0));
    prev[s] = s;
    while (!Q.empty()) {
      Edge e = Q.top();
      Q.pop();
      int v = e.dst;
      for (int i = 0; i < (int)G[v].size(); i++) {
        if (G[v][i].cap > 0 && length[G[v][i].dst] > e.cst + G[v][i].cst) {
          prev[G[v][i].dst] = v;
          Q.push(Edge(v, G[v][i].dst, e.cst + G[v][i].cst, 0, 0));
          prev_num[G[v][i].dst] = i;
          length[G[v][i].dst] = e.cst + G[v][i].cst;
        }
      }
    }
    if (prev[t] < 0) return make_pair(flow, cost);
    int mi = INF;
    int cst = 0;
    for (int v = t; v != s; v = prev[v]) {
      mi = min(mi, G[prev[v]][prev_num[v]].cap);
      cst += G[prev[v]][prev_num[v]].cst;
    }
    if (cst > K) return make_pair(flow, cost);
    if (cst != 0) mi = min(mi, K / cst);
    K -= cst * mi;
    cost += cst * mi;
    for (int v = t; v != s; v = prev[v]) {
      Edge &e = G[prev[v]][prev_num[v]];
      e.cap -= mi;
      G[e.dst][e.rev].cap += mi;
    }
    flow += mi;
  }
}
int frec[26], C[1005];
char s[1005];
int main() {
  string t;
  while (cin >> t) {
    int total = t.size();
    for (int i = 0; i < t.size(); i++) frec[t[i] - 'a']++;
    int n, m;
    scanf("%d", &n);
    int S = 0, T = 27 * n + 27;
    vector<vector<Edge> > G(27 * n + 28);
    for (int i = 1; i <= 26; i++) add_edge(G, 27 * n + i, T, frec[i - 1], 0);
    for (int i = 0; i < n; i++) {
      scanf("%s%d", s, &C[i]);
      m = strlen(s);
      memset(frec, 0, sizeof frec);
      for (int j = 0; j < m; j++) frec[s[j] - 'a']++;
      for (int j = 0; j < 26; j++) {
        add_edge(G, i + 1, n + i * 26 + j + 1, frec[j], i + 1);
        add_edge(G, n + i * 26 + j + 1, 27 * n + j + 1, INF, 0);
      }
      add_edge(G, S, i + 1, C[i], 0);
    }
    pair<int, int> res = flow(G, S, T);
    if (res.first == total)
      printf("%d\n", res.second);
    else
      puts("-1");
  }
}
