#include <bits/stdc++.h>
using namespace std;
long long n, m, tmp, maxi, sum, a[13], sol;
bool visa, visb, visc;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < 10; i++) a[i] = 1000000000007;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> tmp;
    cin >> s;
    visa = 0, visb = 0, visc = 0;
    for (int k = 0; k < s.length(); k++) {
      if (s[k] == 'A') visa = 1;
      if (s[k] == 'B') visb = 1;
      if (s[k] == 'C') visc = 1;
    }
    if (visa) {
      if (visb) {
        if (visc)
          a[7] = min(a[7], tmp);
        else
          a[4] = min(tmp, a[4]);
      } else if (visc)
        a[5] = min(tmp, a[5]);
      else
        a[1] = min(tmp, a[1]);
    } else if (visb) {
      if (visc)
        a[6] = min(a[6], tmp);
      else
        a[2] = min(a[2], tmp);
    } else if (visc)
      a[3] = min(a[3], tmp);
  }
  vector<long long> v;
  v.clear();
  v.push_back(a[7]), v.push_back(a[6] + a[5]), v.push_back(a[6] + a[4]),
      v.push_back(a[6] + a[1]), v.push_back(a[5] + a[4]),
      v.push_back(a[5] + a[2]), v.push_back(a[4] + a[3]),
      v.push_back(a[3] + a[2] + a[1]);
  sol = 1000000000007;
  for (int i = 0; i < v.size(); i++) sol = min(sol, v[i]);
  if (sol >= 1000000000007 - 1001000) sol = -1;
  cout << sol;
  return 0;
}
