#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long A = INT_MAX, B = INT_MAX, C = INT_MAX, AB = INT_MAX, AC = INT_MAX,
            BC = INT_MAX, ABC = INT_MAX;
  for (int i = 0; i < n; i++) {
    long long c;
    string s;
    vector<bool> ma(3, false);
    cin >> c >> s;
    for (auto charac : s) {
      ma[charac - 'A'] = true;
    }
    if (ma[0]) {
      A = min(A, c);
    }
    if (ma[1]) {
      B = min(B, c);
    }
    if (ma[2]) {
      C = min(C, c);
    }
    if (ma[0] && ma[1]) {
      AB = min(AB, c);
    }
    if (ma[0] && ma[2]) {
      AC = min(AC, c);
    }
    if (ma[1] && ma[2]) {
      BC = min(BC, c);
    }
    if (ma[0] && ma[1] && ma[2]) {
      ABC = min(ABC, c);
    }
  }
  long long res = INT_MAX;
  res = min(res, ABC);
  res = min(res, BC + A);
  res = min(res, AC + B);
  res = min(res, AB + C);
  res = min(res, A + B + C);
  cout << (res == INT_MAX ? -1 : res);
  return 0;
}
