#include <bits/stdc++.h>
using namespace std;
int n, inf = 2e12;
string a[] = {"A", "B", "C", "AB", "AC", "BC", "ABC"};
bool found(string s) {
  int mask = 0;
  for (int i = 0; i < ((int)(s).size()); i++) {
    if (s[i] == 'A') mask |= 1;
    if (s[i] == 'B') mask |= 2;
    if (s[i] == 'C') mask |= 4;
  }
  return mask == 7;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  vector<long long> res(8, inf);
  for (int i = 0; i < n; i++) {
    long long p;
    string v;
    cin >> p >> v;
    sort((v).begin(), (v).end());
    if (v == "A")
      res[0] = min(res[0], p);
    else if (v == "B")
      res[1] = min(res[1], p);
    else if (v == "C")
      res[2] = min(res[2], p);
    else if (v == "AB")
      res[3] = min(res[3], p);
    else if (v == "AC")
      res[4] = min(res[4], p);
    else if (v == "BC")
      res[5] = min(res[5], p);
    else if (v == "ABC")
      res[6] = min(res[6], p);
  }
  long long ans = res[6];
  for (int i = 0; i < 7; i++) {
    for (int j = i + 1; j < 7; j++) {
      for (int k = j + 1; k < 7; k++) {
        string A = a[i] + a[j], B = a[i] + a[k], C = a[j] + a[k],
               D = a[i] + a[j] + a[k];
        if (found(A)) ans = min(ans, res[i] + res[j]);
        if (found(B)) ans = min(ans, res[i] + res[k]);
        if (found(C)) ans = min(ans, res[j] + res[k]);
        if (found(D)) ans = min(ans, res[i] + res[j] + res[k]);
      }
    }
  }
  if (ans == inf)
    cout << "-1" << endl;
  else
    cout << ans << endl;
  return 0;
}
