#include <bits/stdc++.h>
using namespace std;
long long int inf = pow(10, 9);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  vector<pair<long long int, string>> v(n);
  for (long long int i = 0; i < n; ++i) cin >> v[i].first >> v[i].second;
  map<string, long long int> ma;
  for (long long int i = 0; i < n; ++i) {
    sort(v[i].second.begin(), v[i].second.end());
    if (ma.find(v[i].second) == ma.end())
      ma[v[i].second] = v[i].first;
    else
      ma[v[i].second] = min(ma[v[i].second], v[i].first);
  }
  vector<long long int> a;
  if (ma.find("A") != ma.end() and ma.find("B") != ma.end() and
      ma.find("C") != ma.end())
    a.push_back(ma["A"] + ma["B"] + ma["C"]);
  if (ma.find("A") != ma.end() and ma.find("BC") != ma.end())
    a.push_back(ma["A"] + ma["BC"]);
  if (ma.find("B") != ma.end() and ma.find("AC") != ma.end())
    a.push_back(ma["B"] + ma["AC"]);
  if (ma.find("C") != ma.end() and ma.find("AB") != ma.end())
    a.push_back(ma["C"] + ma["AB"]);
  if (ma.find("AB") != ma.end() and ma.find("BC") != ma.end())
    a.push_back(ma["AB"] + ma["BC"]);
  if (ma.find("AB") != ma.end() and ma.find("AC") != ma.end())
    a.push_back(ma["AB"] + ma["AC"]);
  if (ma.find("AC") != ma.end() and ma.find("BC") != ma.end())
    a.push_back(ma["AC"] + ma["BC"]);
  if (ma.find("ABC") != ma.end()) a.push_back(ma["ABC"]);
  if (a.size() == 0)
    cout << -1;
  else
    cout << *min_element(a.begin(), a.end());
  return 0;
}
