#include <bits/stdc++.h>
using namespace std;
int n;
string s;
unordered_map<string, long long> M;
int main() {
  long long p, sol;
  cin >> n;
  M["A"] = M["B"] = M["C"] = M["AB"] = M["AC"] = M["BC"] = M["ABC"] = LONG_MAX;
  for (int i = 1; i <= n; i++) {
    cin >> p >> s;
    sort(s.begin(), s.end());
    for (int j = 0; j < s.size(); j++)
      if (s[j] == 'A')
        M["A"] = min(M["A"], p);
      else if (s[j] == 'B')
        M["B"] = min(M["B"], p);
      else
        M["C"] = min(M["C"], p);
    M[s] = min(M[s], p);
  }
  sol = M["A"] + M["B"] + M["C"];
  sol = min(sol, M["AB"] + M["C"]);
  sol = min(sol, M["AC"] + M["B"]);
  sol = min(sol, M["BC"] + M["A"]);
  sol = min(sol, M["ABC"]);
  if (sol >= LONG_MAX)
    cout << "-1\n";
  else
    cout << sol << "\n";
  return 0;
}
