#include <bits/stdc++.h>
using namespace std;
const int inf = 300010;
int n;
map<string, int> war;
void read() {
  cin >> n;
  int c;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> c >> s;
    sort(s.begin(), s.end());
    if (war.count(s) != 0)
      war[s] = min(war[s], c);
    else
      war[s] = c;
  }
}
int getC(string a, string b) {
  if ((war.count(a) != 0) && (war.count(b) != 0))
    return war[a] + war[b];
  else
    return inf;
}
void solve() {
  int ans = inf;
  ans = min(ans, getC("A", "BC"));
  ans = min(ans, getC("B", "AC"));
  ans = min(ans, getC("C", "AB"));
  ans = min(ans, getC("AB", "BC"));
  ans = min(ans, getC("AC", "BC"));
  ans = min(ans, getC("AB", "AC"));
  if (war.count("ABC") != 0) ans = min(ans, war["ABC"]);
  if ((war.count("A") != 0) && (war.count("B") != 0) && (war.count("C") != 0))
    ans = min(ans, war["A"] + war["B"] + war["C"]);
  if (ans != inf)
    cout << ans;
  else
    cout << "-1";
}
int main() {
  read();
  solve();
  return 0;
}
