#include <bits/stdc++.h>
using namespace std;
struct juice {
  int price;
  string vitamin;
};
int main() {
  int n, p, t;
  cin >> n;
  juice s[n];
  for (int i = 0; i < n; i++) {
    cin >> (s[i].price) >> (s[i].vitamin);
    sort(s[i].vitamin.begin(), s[i].vitamin.end());
  }
  map<string, int> m;
  m["A"] = m["B"] = m["C"] = m["AB"] = m["BC"] = m["AC"] = m["ABC"] = INT_MAX;
  for (int i = 0; i < n; i++) {
    p = m[s[i].vitamin];
    if (p > s[i].price) m[s[i].vitamin] = s[i].price;
  }
  t = m["ABC"];
  if (m["A"] != INT_MAX && m["BC"] != INT_MAX) t = min(m["A"] + m["BC"], t);
  if (m["B"] != INT_MAX && m["AC"] != INT_MAX) t = min(m["B"] + m["AC"], t);
  if (m["C"] != INT_MAX && m["AB"] != INT_MAX) t = min(m["C"] + m["AB"], t);
  if (m["A"] != INT_MAX && m["B"] != INT_MAX && m["C"] != INT_MAX)
    t = min(m["A"] + m["B"] + m["C"], t);
  if (m["AB"] != INT_MAX && m["BC"] != INT_MAX) t = min(m["BC"] + m["AB"], t);
  if (m["AC"] != INT_MAX && m["BC"] != INT_MAX) t = min(m["BC"] + m["AC"], t);
  if (m["AC"] != INT_MAX && m["AB"] != INT_MAX) t = min(m["AB"] + m["AC"], t);
  if (t == INT_MAX)
    cout << "-1";
  else
    cout << t;
}
