#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n;
int c[N];
string st[N];
map<string, int> m;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i] >> st[i];
  for (int i = 1; i <= n; i++) sort(st[i].begin(), st[i].end());
  m["A"] = m["B"] = m["C"] = m["AB"] = m["BC"] = m["AC"] = m["ABC"] = 1e7;
  for (int i = 1; i <= n; i++) m[st[i]] = min(c[i], m[st[i]]);
  int ans = 1e7;
  ans = min(ans, m["A"] + m["B"] + m["C"]);
  ans = min(ans, m["A"] + m["BC"]);
  ans = min(ans, m["B"] + m["AC"]);
  ans = min(ans, m["C"] + m["AB"]);
  ans = min(ans, m["AB"] + m["BC"]);
  ans = min(ans, m["AC"] + m["BC"]);
  ans = min(ans, m["AB"] + m["AC"]);
  ans = min(ans, m["ABC"]);
  if (ans == 1e7)
    cout << -1;
  else
    cout << ans;
}
