#include <bits/stdc++.h>
using namespace std;
int MAXI = 10000005;
map<string, int> mp;
int getprice(string s, string t) {
  if (mp[s] and mp[t]) {
    return mp[s] + mp[t];
  }
  return MAXI;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int y;
    string s;
    cin >> y >> s;
    sort(s.begin(), s.end());
    if (!mp[s]) {
      mp[s] = y;
    } else {
      mp[s] = min(mp[s], y);
    }
  }
  int result = MAXI;
  if (mp["A"] and mp["B"] and mp["C"]) {
    result = mp["A"] + mp["B"] + mp["C"];
  }
  if (mp["ABC"]) {
    result = min(result, mp["ABC"]);
  }
  result = min(result, getprice("AC", "AB"));
  result = min(result, getprice("AC", "BC"));
  result = min(result, getprice("AB", "BC"));
  result = min(result, getprice("A", "BC"));
  result = min(result, getprice("B", "AC"));
  result = min(result, getprice("C", "AB"));
  cout << (result == MAXI ? -1 : result) << endl;
  return 0;
}
