#include <bits/stdc++.h>
using namespace std;
int prices[10];
int n, p, ln;
int mask;
int ans;
char s[4];
int main() {
  cin >> n;
  for (int i = 1; i <= 7; ++i) {
    prices[i] = 300001;
  }
  for (int i = 1; i <= n; ++i) {
    cin >> p >> s;
    mask = 0;
    ln = strlen(s);
    for (int j = 0; j < ln; ++j) {
      mask |= (1 << (s[j] - 'A'));
    }
    prices[mask] = min(prices[mask], p);
  }
  ans = 300001;
  ans = min(ans, prices[1] + prices[2] + prices[4]);
  ans = min(ans, prices[7]);
  ans = min(ans, prices[3] + prices[5]);
  ans = min(ans, prices[3] + prices[6]);
  ans = min(ans, prices[5] + prices[6]);
  ans = min(ans, prices[1] + prices[6]);
  ans = min(ans, prices[2] + prices[5]);
  ans = min(ans, prices[4] + prices[3]);
  if (ans >= 300001) {
    ans = -1;
  }
  cout << ans << '\n';
  return 0;
}
