#include <bits/stdc++.h>
using namespace std;
clock_t time_p = clock();
void rtime() {
  time_p = clock() - time_p;
  cout << "\nTime Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC
       << "s\n";
}
inline long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
inline long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }
inline bool isprime(long long n) {
  long long i;
  for (i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return true;
}
inline long long ceil(long long num, long long den) {
  return ((num + den - 1) / den);
}
template <class T>
ostream& operator<<(ostream& os, string V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, set<T> S) {
  os << "{ ";
  for (auto s : S) os << s << " ";
  return os << "}";
}
template <class T>
ostream& operator<<(ostream& os, multiset<T> S) {
  os << "{ ";
  for (auto s : S) os << s << " ";
  return os << "}";
}
template <class T, class T1>
ostream& operator<<(ostream& os, map<T, T1> S) {
  os << "{ ";
  for (auto s : S) os << "(" << s.first << "," << s.second << ") ";
  return os << "}";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long modx = 998244353;
const long long mod = modx;
inline long long add(long long x, long long y, long long mod = modx) {
  x += y;
  if (x >= mod) return x - mod;
  return x % mod;
}
inline long long sub(long long x, long long y, long long mod = modx) {
  x -= y;
  if (x < 0) return x + mod;
  return x;
}
inline long long mul(long long x, long long y, long long mod = modx) {
  return (x * 1ll * y) % mod;
}
inline long long expo(long long x, long long y, long long mod = modx) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = mul(ans, x, mod);
    x = mul(x, x, mod);
    y >>= 1;
  }
  return ans % mod;
}
inline long long inv(long long x, long long mod = modx) {
  return expo(x, mod - 2, mod);
}
long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long MAXN = 1e6 + 100, MAX2N = 2e3 + 10, LG = 31, INF = 2e18;
const long long N = MAXN;
long long n, m, k, x, q, y, z, a[MAXN];
string s[MAXN];
struct edge {
  int to, flow, cap, cost, rev;
};
struct MinCostMaxFlow {
  int nodes;
  vector<int> prio, curflow, prevedge, prevnode, q, pot;
  vector<bool> inqueue;
  vector<vector<edge> > graph;
  MinCostMaxFlow() {}
  MinCostMaxFlow(int n)
      : nodes(n),
        prio(n, 0),
        curflow(n, 0),
        prevedge(n, 0),
        prevnode(n, 0),
        q(n, 0),
        pot(n, 0),
        inqueue(n, 0),
        graph(n) {}
  void addEdge(int source, int to, int capacity, int cost) {
    edge a = {to, 0, capacity, cost, (int)graph[to].size()};
    edge b = {source, 0, 0, -cost, (int)graph[source].size()};
    graph[source].push_back(a);
    graph[to].push_back(b);
  }
  void bellman_ford(int source, vector<int>& dist) {
    fill(dist.begin(), dist.end(), INT_MAX);
    dist[source] = 0;
    int qt = 0;
    q[qt++] = source;
    for (int qh = 0; (qh - qt) % nodes != 0; qh++) {
      int u = q[qh % nodes];
      inqueue[u] = false;
      for (auto& e : graph[u]) {
        if (e.flow >= e.cap) continue;
        int v = e.to;
        int newDist = dist[u] + e.cost;
        if (dist[v] > newDist) {
          dist[v] = newDist;
          if (!inqueue[v]) {
            inqueue[v] = true;
            q[qt++ % nodes] = v;
          }
        }
      }
    }
  }
  pair<int, int> minCostFlow(int source, int dest, int maxflow) {
    bellman_ford(source, pot);
    int flow = 0;
    int flow_cost = 0;
    while (flow < maxflow) {
      priority_queue<pair<int, int>, vector<pair<int, int> >,
                     greater<pair<int, int> > >
          q;
      q.push({0, source});
      fill(prio.begin(), prio.end(), INT_MAX);
      prio[source] = 0;
      curflow[source] = INT_MAX;
      while (!q.empty()) {
        int d = q.top().first;
        int u = q.top().second;
        q.pop();
        if (d != prio[u]) continue;
        for (int i = 0; i < graph[u].size(); i++) {
          edge& e = graph[u][i];
          int v = e.to;
          if (e.flow >= e.cap) continue;
          int newPrio = prio[u] + e.cost + pot[u] - pot[v];
          if (prio[v] > newPrio) {
            prio[v] = newPrio;
            q.push({newPrio, v});
            prevnode[v] = u;
            prevedge[v] = i;
            curflow[v] = min(curflow[u], e.cap - e.flow);
          }
        }
      }
      if (prio[dest] == INT_MAX) break;
      for (int i = 0; i < nodes; i++) pot[i] += prio[i];
      int df = min(curflow[dest], maxflow - flow);
      flow += df;
      for (int v = dest; v != source; v = prevnode[v]) {
        edge& e = graph[prevnode[v]][prevedge[v]];
        e.flow += df;
        graph[v][e.rev].flow -= df;
        flow_cost += df * e.cost;
      }
    }
    return {flow, flow_cost};
  }
};
void solve() {
  string t;
  cin >> t;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> s[i] >> a[i];
  }
  MinCostMaxFlow G(n + 28);
  for (long long i = 1; i <= n; i++) {
    G.addEdge(0, i, a[i], i);
    vector<long long> f(26, 0);
    for (auto c : s[i]) {
      f[c - 'a']++;
    }
    for (long long j = 0; j < 26; j++) {
      G.addEdge(i, n + j + 1, f[j], 0);
    }
  }
  vector<long long> f(26, 0);
  for (auto c : t) f[c - 'a']++;
  for (long long j = 0; j < 26; j++) {
    G.addEdge(n + j + 1, n + 27, f[j], 0);
  }
  pair<long long, long long> g = G.minCostFlow(0, n + 27, (long long)t.size());
  if (g.first == (long long)t.size())
    cout << g.second << "\n";
  else
    cout << -1 << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
}
