#include <bits/stdc++.h>
using namespace std;
const int N = 150;
struct Edge {
  int from, to, capacity, cost;
};
vector<Edge> edges;
int n;
vector<int> adj[N];
int cost[N][N], capacity[N][N];
string s[N];
const int INF = 1e9;
void shortest_paths(int v0, vector<int>& d, vector<int>& p) {
  d.assign(n, INF);
  d[v0] = 0;
  vector<bool> inq(n, false);
  queue<int> q;
  q.push(v0);
  p.assign(n, -1);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inq[u] = false;
    for (int v : adj[u]) {
      if (capacity[u][v] > 0 && d[v] > d[u] + cost[u][v]) {
        d[v] = d[u] + cost[u][v];
        p[v] = u;
        if (!inq[v]) {
          inq[v] = true;
          q.push(v);
        }
      }
    }
  }
}
int min_cost_flow(int K, int s, int t) {
  for (int i = 0; i < edges.size(); ++i) {
    Edge e = edges[i];
    adj[e.from].push_back(e.to);
    adj[e.to].push_back(e.from);
    cost[e.from][e.to] = e.cost;
    cost[e.to][e.from] = -e.cost;
    capacity[e.from][e.to] = e.capacity;
  }
  int flow = 0;
  int cost = 0;
  vector<int> d, p;
  while (flow < K) {
    shortest_paths(s, d, p);
    if (d[t] == INF) break;
    int f = K - flow;
    int cur = t;
    while (cur != s) {
      f = min(f, capacity[p[cur]][cur]);
      cur = p[cur];
    }
    flow += f;
    cost += f * d[t];
    cur = t;
    while (cur != s) {
      capacity[p[cur]][cur] -= f;
      capacity[cur][p[cur]] += f;
      cur = p[cur];
    }
  }
  if (flow < K)
    return -1;
  else
    return cost;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string t;
  int m, x, k;
  cin >> t >> m;
  k = m + 1;
  n = m + 30;
  int kol[26];
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> x;
    edges.push_back({0, i + 1, x, i + 1});
    for (int j = 0; j < 26; ++j) kol[j] = 0;
    for (int j = 0; j < s[i].length(); ++j) kol[s[i][j] - 'a']++;
    for (int j = 0; j < 26; ++j) edges.push_back({i + 1, m + 1 + j, kol[j], 0});
  }
  for (int i = 0; i < 26; ++i) kol[i] = 0;
  for (int i = 0; i < t.length(); ++i) kol[t[i] - 'a']++;
  for (int i = 0; i < 26; ++i) edges.push_back({m + 1 + i, m + 29, kol[i], 0});
  cout << min_cost_flow(t.length(), 0, m + 29) << '\n';
}
