#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxpq = priority_queue<T>;
inline long long CC(long long n, long long y) {
  return (((n) + (y - 1) - 1) / (y - 1)) - (((n) + (y)-1) / (y));
}
inline long long FF(long long n, long long y) { return n / y - n / (y + 1); }
inline long long __gcd(long long a, long long b) {
  return !b ? a : __gcd(b, a % b);
}
inline int add(int a, int b, int p = 1000000007) {
  int c = a + b;
  if (c >= p) c -= p;
  return c;
}
inline int sub(int a, int b, int p = 1000000007) {
  int c = a - b;
  if (c < 0) c += p;
  return c;
}
inline int mul(int a, int b, int p = 1000000007) { return (a * 1ll * b) % p; }
const long long inf = 1e9;
vector<long long> adj[3005];
long long capacity[3005][3005], cost[3005][3005];
long long d[3005], par[3005], M[3005];
struct MinCostFlow {
  long long n;
  MinCostFlow(long long _n) : n(_n) {
    for (long long i = (0); i < (n); i++) adj[i].clear();
    memset(capacity, 0, sizeof capacity);
    memset(cost, 0, sizeof cost);
  }
  void add_edge(long long u, long long v, long long cap, long long cst) {
    adj[u].push_back(v);
    adj[v].push_back(u);
    capacity[u][v] = cap;
    capacity[v][u] = 0;
    cost[u][v] = cst;
    cost[v][u] = -cst;
  }
  void shortest_paths(long long src) {
    for (long long i = 0; i < n; i++) {
      d[i] = inf;
      par[i] = -1;
      M[i] = 2;
    }
    d[src] = 0;
    deque<long long> dq;
    dq.push_back(src);
    while (!dq.empty()) {
      long long u = dq.front();
      dq.pop_front();
      M[u] = 0;
      for (long long v : adj[u]) {
        long long w = cost[u][v];
        if (capacity[u][v] > 0 && d[v] > d[u] + w) {
          d[v] = d[u] + w;
          par[v] = u;
          if (M[v] == 0) {
            M[v] = 1;
            dq.push_front(v);
          } else if (M[v] == 2) {
            M[v] = 1;
            dq.push_back(v);
          }
        }
      }
    }
  }
  pair<long long, long long> min_cost_flow(long long s, long long t,
                                           long long K = inf,
                                           long long cur_flow = 0,
                                           long long cur_cost = 0) {
    long long flow, cost;
    flow = cur_flow;
    cost = cur_cost;
    while (flow < K) {
      shortest_paths(s);
      if (d[t] == inf) break;
      long long f = K - flow;
      long long cur = t;
      while (cur != s) {
        f = min(f, capacity[par[cur]][cur]);
        cur = par[cur];
      }
      flow += f;
      cost += d[t] * f;
      cur = t;
      while (cur != s) {
        long long p = par[cur];
        capacity[p][cur] -= f;
        capacity[cur][p] += f;
        cur = p;
      }
    }
    if (K != inf && flow < K)
      return {inf, -1};
    else
      return {cost, flow};
  }
};
string t, s[200005];
long long tot[200005][26];
long long freq[26];
long long n, mx[200005];
const long long b = 26;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  clock_t clk = clock();
  cerr << "I will return...\n";
  cin >> t >> n;
  for (char c : t) freq[c - 'a']++;
  for (long long i = (0); i < (n); i++) {
    cin >> s[i] >> mx[i];
    for (char c : s[i]) tot[i][c - 'a']++;
  }
  MinCostFlow mf(n + b + 2);
  for (long long i = 1; i <= n; i++) mf.add_edge(0, i, mx[i - 1], i);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= b; j++) {
      mf.add_edge(i, n + j, tot[i - 1][j - 1], 0);
    }
  }
  for (long long i = 1; i <= b; i++)
    mf.add_edge(n + i, n + b + 1, freq[i - 1], 0);
  auto p = mf.min_cost_flow(0, n + b + 1);
  __f("p.fi, p.se", p.first, p.second);
  if (p.second != t.size()) {
    cout << -1 << '\n';
  } else {
    cout << p.first << '\n';
  }
  cerr << "...don't you ever hang your head.\n";
  cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC
       << '\n';
}
