#include <bits/stdc++.h>
using namespace std;
vector<long long int> primes;
void sieve() {
  bool prime[10000001];
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (long long int i = 2; i * i <= 10000001; i++) {
    if (prime[i]) {
      for (long long int j = i * i; j < 10000001; j += i) prime[j] = false;
    }
  }
  long long int count = 0;
  for (long long int i = 0; i < 10000001; i++) {
    if (prime[i]) count++;
    primes.push_back(count);
  }
}
void solve() {
  long long int n;
  cin >> n;
  long long int e = 1e7;
  long long int c;
  string str;
  vector<long long int> A, B, C, AB, BC, AC, ABC;
  A.push_back(e);
  B.push_back(e);
  C.push_back(e);
  AB.push_back(e);
  BC.push_back(e);
  AC.push_back(e);
  ABC.push_back(e);
  long long int ans = INT_MAX;
  while (n--) {
    cin >> c >> str;
    sort(str.begin(), str.end());
    if (str == "C")
      C.push_back(c);
    else if (str == "A")
      A.push_back(c);
    else if (str == "B")
      B.push_back(c);
    else if (str == "AB")
      AB.push_back(c);
    else if (str == "AC")
      AC.push_back(c);
    else if (str == "BC")
      BC.push_back(c);
    else
      ABC.push_back(c);
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  sort(AB.begin(), AB.end());
  sort(AC.begin(), AC.end());
  sort(BC.begin(), BC.end());
  sort(ABC.begin(), ABC.end());
  long long int ans1 = min(
      A[0] + ABC[0],
      min(A[0] + BC[0], min(A[0] + ABC[0],
                            min(A[0] + BC[0], min(A[0] + B[0] + ABC[0],
                                                  min(A[0] + B[0] + AC[0],
                                                      A[0] + B[0] + BC[0]))))));
  long long int ans2 = min(
      B[0] + ABC[0],
      min(B[0] + AC[0], min(A[0] + C[0] + ABC[0],
                            min(A[0] + C[0] + AB[0], A[0] + C[0] + BC[0]))));
  long long int ans3 = min(
      C[0] + ABC[0],
      min(C[0] + AB[0], min(C[0] + B[0] + ABC[0],
                            min(C[0] + B[0] + AB[0], C[0] + B[0] + AC[0]))));
  long long int ans4 = min(AB[0] + BC[0], min(AB[0] + AC[0], AC[0] + BC[0]));
  long long int ans5 = min(A[0] + B[0] + C[0], ABC[0]);
  ans = min(ans, min(ans5, min(ans4, min(ans3, min(ans1, ans2)))));
  (ans >= e) ? cout << -1 : cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
}
