#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int inf = 0x3f3f3f3f3f3f3f3fLL;
long long int i, j, k;
void solve(void);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int t = 1;
  while (t--) solve();
  return 0;
}
class MinCostMaxFlow {
 public:
  int n;
  vector<vector<int>> cost, capacity;
  vector<vector<int>> graph;
  vector<int> dist, parent;
  void SPFA(int s) {
    dist.assign(n + 1, mod);
    parent.assign(n + 1, -1);
    vector<int> inqueue(n + 1, 0);
    dist[s] = 0;
    inqueue[s] = 1;
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
      int id = q.front();
      q.pop();
      inqueue[id] = 0;
      for (auto to : graph[id])
        if (capacity[id][to])
          if (dist[id] + cost[id][to] < dist[to]) {
            dist[to] = dist[id] + cost[id][to];
            parent[to] = id;
            if (!inqueue[to]) {
              inqueue[to] = 1;
              q.push(to);
            }
          }
    }
  }
  void DEPape(int s) {
    dist.assign(n + 1, mod);
    parent.assign(n + 1, -1);
    vector<int> m(n + 1, 2);
    deque<int> dq;
    dist[s] = 0;
    m[s] = 1;
    dq.push_back(s);
    while (!dq.empty()) {
      int id = dq.front();
      dq.pop_front();
      m[id] = 0;
      for (auto to : graph[id])
        if (capacity[id][to])
          if (dist[to] > dist[id] + cost[id][to]) {
            dist[to] = dist[id] + cost[id][to];
            parent[to] = id;
            if (m[to] == 2) {
              dq.push_back(to);
              m[to] = 1;
            } else if (m[to] == 0) {
              dq.push_front(to);
              m[to] = 1;
            }
          }
    }
  }
  pair<long long int, long long int> mincost_maxflow(int s, int t,
                                                     int req_flow) {
    int curflow = 0;
    long long int mincost = 0;
    while (curflow < req_flow) {
      DEPape(s);
      if (dist[t] == mod) break;
      int id = t, F = mod;
      while (parent[id] != -1) {
        F = ((F) < (capacity[parent[id]][id]) ? (F)
                                              : (capacity[parent[id]][id]));
        id = parent[id];
      }
      F = ((F) < (req_flow - curflow) ? (F) : (req_flow - curflow));
      curflow += F;
      id = t;
      while (parent[id] != -1) {
        int p = parent[id];
        mincost += F * cost[p][id];
        capacity[p][id] -= F;
        capacity[id][p] += F;
        id = p;
      }
    }
    return make_pair(mincost, curflow);
  }
  MinCostMaxFlow(int siz) {
    n = siz;
    cost.clear();
    graph.clear();
    capacity.clear();
    cost.resize(n + 1, vector<int>(n + 1, 0));
    capacity.resize(n + 1, vector<int>(n + 1, 0));
    graph.resize(n + 1);
  }
};
void solve() {
  string t;
  cin >> t;
  int cnt[26] = {0};
  for (i = (0); i <= ((long long)t.size() - 1); ++i) ++cnt[t[i] - 'a'];
  int n;
  cin >> n;
  MinCostMaxFlow mcmf(205);
  for (i = (1); i <= (n); ++i) {
    string s;
    cin >> s;
    int a;
    cin >> a;
    mcmf.graph[0].emplace_back(i);
    mcmf.graph[i].emplace_back(0);
    mcmf.capacity[0][i] = a;
    mcmf.cost[0][i] = i;
    mcmf.cost[i][0] = -i;
    int cnt[26] = {0};
    for (j = (0); j <= ((long long)s.size() - 1); ++j) ++cnt[s[j] - 'a'];
    for (j = (0); j <= (25); ++j) {
      mcmf.graph[i].emplace_back(105 + j);
      mcmf.graph[105 + j].emplace_back(i);
      mcmf.capacity[i][105 + j] = cnt[j];
    }
  }
  for (j = (0); j <= (25); ++j) {
    mcmf.graph[105 + j].emplace_back(150);
    mcmf.graph[150].emplace_back(105 + j);
    mcmf.capacity[105 + j][150] = cnt[j];
  }
  pair<long long int, long long int> p = mcmf.mincost_maxflow(0, 150, mod);
  if (p.second < (long long)t.size())
    cout << "-1" << '\n';
  else
    cout << p.first << '\n';
}
