#include <bits/stdc++.h>
using namespace std;
long long sum = 10000000000000000;
int main() {
  string s;
  map<string, int> mp;
  int n, a;
  cin >> n;
  while (n--) {
    cin >> a;
    cin >> s;
    if (s.size() == 1) {
      if (mp[s] == 0)
        mp[s] = a;
      else if (a < mp[s])
        mp[s] = a;
    } else {
      sort(s.begin(), s.end());
      if (mp[s] == 0)
        mp[s] = a;
      else if (a < mp[s])
        mp[s] = a;
    }
  }
  if (mp["A"] && mp["B"] && mp["C"]) sum = mp["A"] + mp["B"] + mp["C"];
  if (mp["A"] && mp["BC"] && sum > mp["A"] + mp["BC"]) sum = mp["A"] + mp["BC"];
  if (mp["B"] && mp["AC"] && sum > mp["B"] + mp["AC"]) sum = mp["B"] + mp["AC"];
  if (mp["C"] && mp["AB"] && sum > mp["C"] + mp["AB"]) sum = mp["C"] + mp["AB"];
  if (mp["ABC"] && sum > mp["ABC"]) sum = mp["ABC"];
  if (mp["AB"] && mp["AC"] && sum > mp["AB"] + mp["AC"])
    sum = mp["AB"] + mp["AC"];
  if (mp["AB"] && mp["BC"] && sum > mp["BC"] + mp["AB"])
    sum = mp["BC"] + mp["AB"];
  if (mp["AC"] && mp["BC"] && sum > mp["AC"] + mp["BC"])
    sum = mp["AC"] + mp["BC"];
  if (sum == 10000000000000000)
    cout << -1;
  else
    cout << sum;
  return 0;
}
