#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> A(1, 1e9), B(1, 1e9), C(1, 1e9);
  vector<long long> AB(1, 1e9), BC(1, 1e9), CA(1, 1e9), ABC(1, 1e9);
  for (int i = 0; i < n; i++) {
    long long x;
    string s;
    cin >> x >> s;
    sort(s.begin(), s.end());
    if (s == "A") A.push_back(x);
    if (s == "B") B.push_back(x);
    if (s == "C") C.push_back(x);
    if (s == "AB") AB.push_back(x);
    if (s == "BC") BC.push_back(x);
    if (s == "AC") CA.push_back(x);
    if (s == "ABC") ABC.push_back(x);
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  sort(AB.begin(), AB.end());
  sort(BC.begin(), BC.end());
  sort(CA.begin(), CA.end());
  sort(ABC.begin(), ABC.end());
  long long s0 = ABC[0];
  long long s1 = AB[0] + C[0];
  long long s2 = BC[0] + A[0];
  long long s3 = CA[0] + B[0];
  long long s4 = A[0] + B[0] + C[0];
  long long s5 = AB[0] + BC[0];
  long long s6 = BC[0] + CA[0];
  long long s7 = CA[0] + AB[0];
  long long mi =
      min(s0, min(s1, min(s2, min(s3, min(s4, min(s5, min(s6, s7)))))));
  if (mi >= 1e8)
    cout << -1 << endl;
  else
    cout << mi << endl;
}
