#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 30;
long long inf = 1e18;
long long n, cc[maxn], a = inf, b = inf, c = inf, ab = inf, ac = inf, bc = inf,
                       abc = inf;
string s;
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> cc[i] >> s;
    bool A = 0, B = 0, C = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'A') A = 1;
      if (s[i] == 'B') B = 1;
      if (s[i] == 'C') C = 1;
    }
    if (A == 1 and B == 0 and C == 0) a = min(a, cc[i]);
    if (B == 1 and A == 0 and C == 0) b = min(b, cc[i]);
    if (C == 1 and B == 0 and A == 0) c = min(c, cc[i]);
    if (A == 1 and B == 1 and C == 0) ab = min(ab, cc[i]);
    if (A == 1 and B == 0 and C == 1) ac = min(ac, cc[i]);
    if (A == 0 and B == 1 and C == 1) bc = min(bc, cc[i]);
    if (A == 1 and B == 1 and C == 1) abc = min(abc, cc[i]);
  }
  long long ans = inf;
  ans = min(ans, a + b + c);
  ans = min(ans, a + bc);
  ans = min(ans, ab + c);
  ans = min(ans, ac + b);
  ans = min(ans, abc);
  ans = min(ans, ab + bc);
  ans = min(ans, ac + bc);
  ans = min(ans, ab + ac);
  ans = min(ans, ab + abc);
  ans = min(ans, ac + abc);
  ans = min(ans, bc + abc);
  if (ans == inf)
    cout << -1;
  else
    cout << ans << endl;
}
