#include <bits/stdc++.h>
using namespace std;
const int N = 128;
vector<int> adj[N];
int n, g[N][N], vis[N], qu[N], par[N], vs, can[101];
char s[101];
void addEdge(int u, int v, int c) {
  g[u][v] = c;
  adj[u].push_back(v);
  adj[v].push_back(u);
}
bool DFS(int v, int tar) {
  if (v == tar) return true;
  vis[v] = vs;
  bool can = false;
  for (size_t i = 0; i < adj[v].size() && !can; ++i) {
    int u = adj[v][i];
    if (vis[u] == vs || !g[v][u]) continue;
    par[u] = v;
    can |= DFS(u, tar);
  }
  return can;
}
int maxFlow(int str, int tar) {
  int flow = 0;
  while (true) {
    ++vs;
    if (!DFS(str, tar)) break;
    ++flow;
    for (int u = tar; u != str; u = par[u]) {
      int v = par[u];
      ++g[u][v];
      --g[v][u];
    }
  }
  return flow;
}
int main(int argc, char **argv) {
  scanf("%s%d", s, &n);
  int len = strlen(s), f[26] = {}, id = 0, hs[26] = {};
  for (int i = 0; i < len; ++i) {
    int u = s[i] - 'a';
    if (!f[u]) hs[u] = id++;
    ++f[u];
  }
  for (int i = 0; i < 26; ++i)
    if (f[i]) addEdge(n + hs[i] + 1, n + id + 1, f[i]);
  for (int i = 1; i <= n; ++i) {
    scanf("%s%d", s, &can[i]);
    addEdge(0, i, can[i]);
    int cnt[26] = {};
    for (int j = 0; s[j]; ++j) ++cnt[s[j] - 'a'];
    for (int j = 0; j < 26; ++j)
      if (f[j] && cnt[j]) addEdge(i, n + hs[j] + 1, cnt[j]);
  }
  for (int i = 0; i <= n + id + 1; ++i) sort(adj[i].begin(), adj[i].end());
  if (maxFlow(0, n + id + 1) != len) {
    puts("-1");
    return 0;
  }
  int res = 0;
  for (int i = 1; i <= n; ++i) res += (can[i] - g[0][i]) * i;
  printf("%d\n", res);
  return 0;
}
