#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, long long> prices;
  prices["A"] = (1LL << 31);
  prices["B"] = (1LL << 31);
  prices["C"] = (1LL << 31);
  prices["AB"] = (1LL << 31);
  prices["BC"] = (1LL << 31);
  prices["AC"] = (1LL << 31);
  prices["ABC"] = (1LL << 31);
  while (n--) {
    long long p;
    string v;
    cin >> p >> v;
    sort(v.begin(), v.end());
    prices[v] = min(prices[v], p);
  }
  long long min = (1LL << 31);
  min = std::min(min, prices["A"] + prices["B"] + prices["C"]);
  min = std::min(min, prices["A"] + prices["BC"]);
  min = std::min(min, prices["B"] + prices["AC"]);
  min = std::min(min, prices["C"] + prices["AB"]);
  min = std::min(min, prices["AB"] + prices["BC"]);
  min = std::min(min, prices["AB"] + prices["AC"]);
  min = std::min(min, prices["BC"] + prices["AC"]);
  min = std::min(min, prices["ABC"]);
  if (min >= (1LL << 31))
    cout << -1 << endl;
  else
    cout << min << endl;
  return 0;
}
