#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &S, const vector<T> &v) {
  S << "(";
  for (int i = 0; i < v.size(); i++) {
    if (i) S << ", ";
    S << v[i];
  }
  S << ")";
  return S;
}
template <class T1, class T2>
ostream &operator<<(ostream &S, const pair<T1, T2> &p) {
  S << "(" << p.first << ", " << p.second << ")";
  return S;
}
template <class T>
T abs(T num) {
  return num > 0 ? num : -num;
}
template <class T>
T sqr(T num) {
  return num * num;
}
struct edge {
  int u, v, flow, cap, cost;
};
const int MAXN = 101;
string t;
int N;
string str;
int mx;
int freq[26], freq2[26];
int dist[MAXN << 1], par[MAXN << 1];
bool inq[MAXN << 1];
vector<edge> e;
vector<int> adj[MAXN << 1];
void add_edge(int u, int v, int cap, int cost) {
  edge e1 = {u, v, 0, cap, cost};
  edge e2 = {v, u, 0, 0, -cost};
  adj[u].push_back(e.size());
  e.push_back(e1);
  adj[v].push_back(e.size());
  e.push_back(e2);
}
bool spfa() {
  fill(dist, dist + N + 30, 0x7FFFFFFF);
  memset(inq, false, sizeof inq);
  memset(par, -1, sizeof par);
  queue<int> q;
  q.push(N + 28);
  dist[N + 28] = 0;
  inq[N + 28] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inq[u] = false;
    for (int i = 0; i < (int)adj[u].size(); i++) {
      int id = adj[u][i], v = e[id].v;
      if (dist[v] > dist[u] + e[id].cost && e[id].flow < e[id].cap) {
        dist[v] = dist[u] + e[id].cost;
        par[v] = id;
        if (!inq[v]) {
          inq[v] = true;
          q.push(v);
        }
      }
    }
  }
  return par[N + 27] != -1;
}
pair<int, int> aug() {
  int flow = 0x7FFFFFFF, cost = 0;
  for (int i = par[N + 27]; i >= 0; i = par[e[i].u])
    flow = min(flow, e[i].cap - e[i].flow);
  for (int i = par[N + 27]; i >= 0; i = par[e[i].u]) {
    e[i].flow += flow;
    e[i ^ 1].flow -= flow;
  }
  cost = flow * dist[N + 27];
  return make_pair(flow, cost);
}
pair<int, int> minCostFlow() {
  int flow = 0, cost = 0;
  while (spfa()) {
    pair<int, int> cur = aug();
    flow += cur.first;
    cost += cur.second;
  }
  return make_pair(flow, cost);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> t >> N;
  for (int i = 0; i < (int)t.length(); i++) freq[t[i] - 'a']++;
  for (int i = 1; i <= N; i++) {
    cin >> str >> mx;
    add_edge(0, i, mx, i);
    memset(freq2, 0, sizeof freq2);
    for (int j = 0; j < (int)str.length(); j++) freq2[str[j] - 'a']++;
    for (int j = 0; j < 26; j++) add_edge(i, N + j + 1, freq2[j], 0);
  }
  for (int i = 0; i < 26; i++) add_edge(N + i + 1, N + 27, freq[i], 0);
  add_edge(N + 28, 0, t.length(), 0);
  pair<int, int> ans = minCostFlow();
  if (ans.first != t.length())
    cout << -1 << endl;
  else
    cout << ans.second << endl;
  return 0;
}
