#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
vector<int> b;
int f[8];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int p, c = 0;
    string s;
    cin >> p >> s;
    for (int j = 0; j < s.size(); ++j) c |= (1 << (s[j] - 'A'));
    a.push_back(p);
    b.push_back(c);
  }
  f[0] = 0;
  for (int i = 1; i < 8; ++i) f[i] = -1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 8; ++j)
      if (f[j] >= 0) {
        int c = j | b[i];
        if (f[c] == -1 || f[c] >= f[j] + a[i]) f[c] = f[j] + a[i];
      }
  }
  cout << f[7] << endl;
  return 0;
}
