#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, int> mapp;
  int mina = 10000000, minb = 10000000, minc = 10000000, minab = 10000000,
      minac = 10000000, minbc = 10000000, min3 = 10000000;
  int x;
  string na;
  for (int i = 0; i < n; i++) {
    cin >> x >> na;
    sort(na.begin(), na.end());
    if (na.length() == 3) {
      min3 = min(x, min3);
    } else if (na == "A") {
      mina = min(x, mina);
    } else if (na == "B") {
      minb = min(x, minb);
    } else if (na == "C") {
      minc = min(x, minc);
    } else if (na == "AB") {
      minab = min(x, minab);
    } else if (na == "AC") {
      minac = min(x, minac);
    } else if (na == "BC") {
      minbc = min(x, minbc);
    }
  }
  min3 = min(min3, minab + minc);
  min3 = min(min3, minac + minb);
  min3 = min(min3, minbc + mina);
  min3 = min(min3, mina + minb + minc);
  min3 = min(min3, minab + minbc);
  min3 = min(min3, minab + minac);
  min3 = min(min3, minac + minbc);
  if (min3 > 1000000) {
    cout << "-1" << endl;
  } else {
    cout << min3 << endl;
  }
  return 0;
}
