#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    heapp;
priority_queue<pair<int, int> > heapp2;
vector<int> tree[100006];
vector<pair<int, int> > tree1[100006];
class comp {
 public:
  bool operator()(pair<int, int> n1, pair<int, int> n2) {
    return (n1.second > n2.second);
  }
};
long long int mini(long long int lk, long long int fh) {
  if (lk > fh) {
    return fh;
  } else
    return lk;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  long long int ab = INT_MAX, bc = INT_MAX, ac = INT_MAX, a = INT_MAX,
                b = INT_MAX, C = INT_MAX, abc = INT_MAX;
  int k = 0;
  while (n--) {
    string s;
    int c = 0;
    cin >> c >> s;
    if (s.find("ABC") != -1 || s.find("ACB") != -1 || s.find("BAC") != -1 ||
        s.find("BCA") != -1 || s.find("CAB") != -1 || s.find("CBA") != -1) {
      abc = mini(c, abc);
    } else if (s.find("AB") != -1 || s.find("BA") != -1) {
      ab = mini(ab, c);
    } else if (s.find("CB") != -1 || s.find("BC") != -1) {
      bc = mini(bc, c);
    } else if (s.find("AC") != -1 || s.find("CA") != -1) {
      ac = mini(ac, c);
    } else if (s.find('A') != -1) {
      a = mini(a, c);
    } else if (s.find('B') != -1) {
      b = mini(b, c);
    } else if (s.find('C') != -1) {
      C = mini(C, c);
    }
    k++;
  }
  long long int ans = INT_MAX;
  ans = mini(abc, ans);
  ans = mini(ans, ab + C);
  ans = mini(ans, bc + a);
  ans = mini(ans, ac + b);
  ans = mini(ans, ab + bc);
  ans = mini(ans, ac + ab);
  ans = mini(ans, bc + ac);
  ans = mini(ans, a + b + C);
  if (ans == INT_MAX) ans = -1;
  cout << ans << endl;
  return 0;
}
