#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 50;
const int INF = 1e8 + 100;
int val[MAXN], vec[MAXN];
int dp[MAXN][100];
int n, t;
bool check(int x) { return x == ((1 << 3) - 1); }
int solve(int id, int suco) {
  if (check(suco)) return 0;
  if (id >= n) return (INF);
  if (dp[id][suco] != -1) return dp[id][suco];
  int ans = INF;
  ans = min(solve(id + 1, (suco | vec[id])) + val[id], solve(id + 1, suco));
  return dp[id][suco] = ans;
}
int32_t main() {
  cin >> n;
  string s;
  for (int i = 0; i < n; i++) {
    int aux = 0;
    cin >> t >> s;
    for (auto c : s) aux |= (1 << (int(c - 'A')));
    vec[i] = aux;
    val[i] = t;
  }
  memset(dp, -1, sizeof dp);
  int ans = solve(0, 0);
  cout << (ans == INF ? -1 : ans) << '\n';
  return 0;
}
