#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long> dp(8, INT_MAX);
  long long n, p;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p >> s;
    int k = 0;
    for (char c : s) {
      k |= 1 << (c - 'A');
    }
    dp[k] = min(dp[k], p);
  }
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 8; j++) {
      for (int k = 0; k < 8; k++) {
        dp[j | k] = min(dp[j | k], dp[j] + dp[k]);
      }
    }
  }
  if (dp[7] < INT_MAX) {
    cout << dp[7] << endl;
  } else {
    cout << -1 << endl;
  }
}
