#include <bits/stdc++.h>
using namespace std;
string s;
int aa;
vector<long long> a, b, c, ab, bc, ac, abc;
long long ans = 1e18, n;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> aa;
    cin >> s;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == 'A')
        a.push_back(aa);
      else if (s[j] == 'B')
        b.push_back(aa);
      else
        c.push_back(aa);
    }
    if (s.length() == 2 && s.find('A') != -1 && s.find('B') != -1)
      ab.push_back(aa);
    if (s.length() == 2 && s.find('A') != -1 && s.find('C') != -1)
      ac.push_back(aa);
    else if (s.length() == 2 && s.find('C') != -1 && s.find('B') != -1)
      bc.push_back(aa);
    else if (s.length() == 3)
      abc.push_back(aa);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  sort(ac.begin(), ac.end());
  sort(bc.begin(), bc.end());
  sort(ab.begin(), ab.end());
  sort(abc.begin(), abc.end());
  if (ac.size() != 0 && b.size() != 0) ans = min(ac[0] + b[0], ans);
  if (bc.size() != 0 && a.size() != 0) ans = min(bc[0] + a[0], ans);
  if (ab.size() != 0 && c.size() != 0) ans = min(ab[0] + c[0], ans);
  if (abc.size() != 0) ans = min(abc[0], ans);
  if (a.size() != 0 && b.size() != 0 && c.size() != 0)
    ans = min(a[0] + b[0] + c[0], ans);
  cout << (ans == 1e18 ? -1 : ans);
  return 0;
}
