#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T>
void uin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <typename T>
void uax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}
const long long N = 105;
const long long INF = 1e18 + 228;
namespace MCMF {
const long long N = 100000;
struct edge {
  long long from, to, cap, flow, cost;
  long long rem() { return cap - flow; }
  edge() {}
  edge(long long _from, long long _to, long long _cap, long long _flow,
       long long _cost) {
    from = _from;
    to = _to;
    cap = _cap;
    flow = _flow;
    cost = _cost;
  }
};
long long n;
vector<edge> e;
vector<long long> g[N];
long long cap[N], dist[N], pre[N], ptr = 0;
bool inqueue[N];
long long mincost = 0, maxflow = 0;
void add_edge(long long u, long long v, long long cap, long long cost) {
  e.push_back(edge(u, v, cap, 0, cost));
  g[u].push_back(ptr++);
  e.push_back(edge(v, u, 0, 0, -cost));
  g[v].push_back(ptr++);
}
bool flow(long long s, long long t) {
  for (long long i = 1; i <= n; ++i) {
    dist[i] = INF;
    pre[i] = -1;
  }
  dist[s] = 0;
  inqueue[s] = 1;
  queue<long long> q;
  q.push(s);
  cap[s] = INF;
  while (!q.empty()) {
    long long v = q.front();
    q.pop();
    inqueue[v] = 0;
    for (long long num : g[v]) {
      long long to = e[num].to;
      if (e[num].rem() && dist[v] + e[num].cost < dist[to]) {
        dist[to] = dist[v] + e[num].cost;
        cap[to] = min(cap[v], e[num].rem());
        pre[to] = num;
        if (!inqueue[to]) {
          inqueue[to] = 1;
          q.push(to);
        }
      }
    }
  }
  if (dist[t] == INF) return 0;
  maxflow += cap[t];
  mincost += dist[t] * cap[t];
  long long v = t;
  while (v != s) {
    long long i = pre[v];
    e[i].flow += cap[t];
    e[i ^ 1].flow -= cap[t];
    v = e[i].from;
  }
  return 1;
}
void mcmf(long long s, long long t) {
  mincost = 0;
  maxflow = 0;
  for (long long i = 1; i <= n; ++i) inqueue[i] = 0;
  while (flow(s, t)) {
  }
}
}  // namespace MCMF
string str[N];
long long A[N];
long long CNT[105][27];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string T;
  cin >> T;
  long long n;
  cin >> n;
  long long s = 1;
  long long t = 2;
  long long ptr = 3;
  for (long long i = 1; i <= n; ++i) {
    cin >> str[i];
    cin >> A[i];
  }
  for (long long i = 1; i <= n; ++i) {
    for (char c : str[i]) ++CNT[i][c - 'a' + 1];
  }
  long long cnt[27];
  memset(cnt, 0, sizeof cnt);
  for (char c : T) ++cnt[c - 'a' + 1];
  vector<long long> VV(30);
  for (long long i = 1; i <= 26; ++i) {
    if (!cnt[i]) continue;
    MCMF::add_edge(s, ptr++, cnt[i], 0);
    VV[i] = ptr - 1;
  }
  vector<long long> num(n + 1);
  for (long long i = 1; i <= n; ++i) num[i] = ptr++;
  for (long long c = 1; c <= 26; ++c) {
    for (long long i = 1; i <= n; ++i) {
      if (CNT[i][c]) {
        MCMF::add_edge(VV[c], num[i], CNT[i][c], 0);
      }
    }
  }
  for (long long i = 1; i <= n; ++i) {
    MCMF::add_edge(num[i], t, A[i], i);
  }
  MCMF::n = ptr - 1;
  MCMF::mcmf(s, t);
  if (MCMF::maxflow != (long long)T.size())
    cout << -1 << endl;
  else
    cout << MCMF::mincost << endl;
  return 0;
}
