#include <bits/stdc++.h>
using namespace std;
int main() {
  string second;
  int i, t, ans = 1000000001, n, mina, minb, minc;
  cin >> t;
  string sa[] = {"A", "B", "C", "AB", "BC", "AC", "ABC"};
  map<string, int> m;
  for (long long i = 0; i < t; i++) {
    cin >> n >> second;
    sort(second.begin(), second.end());
    if (m[second] == 0) {
      m[second] = n;
    } else
      m[second] = min(m[second], n);
  }
  for (i = 0; i < 7; i++) {
    if (m[sa[i]] == 0) m[sa[i]] = 1000000001;
  }
  if (m["ABC"] != 1000000001) ans = m["ABC"];
  if ((m["A"] != 1000000001) && (m["B"] != 1000000001) &&
      (m["C"] != 1000000001))
    ans = min(ans, m["A"] + m["B"] + m["C"]);
  mina = min(m["A"], m["AB"]);
  mina = min(mina, m["AC"]);
  minb = min(m["B"], m["AB"]);
  minb = min(minb, m["BC"]);
  minc = min(m["C"], m["AC"]);
  minc = min(minc, m["BC"]);
  ans = min(ans, mina + m["BC"]);
  ans = min(ans, minb + m["AC"]);
  ans = min(ans, minc + m["AB"]);
  if (ans == 1000000001)
    cout << -1;
  else
    cout << ans << endl;
  return 0;
}
