#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll nmax = 1e3 + 16, MAX = 1e9 + 1;
ll n, val[nmax], vtm[nmax], f[nmax][8], res = MAX;
string contain;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> val[i] >> contain;
    for (auto j : contain) vtm[i] |= (1 << (j - 'A'));
  }
  memset(f, MAX, sizeof(f));
  for (ll i = 1; i <= n; i++) f[i][vtm[i]] = val[i];
  for (ll i = 1; i < n; i++)
    for (ll mask = 1; mask < 8; mask++) {
      f[i + 1][mask] = min(f[i + 1][mask], f[i][mask]);
      f[i + 1][mask | vtm[i + 1]] =
          min(f[i + 1][mask | vtm[i + 1]], f[i][mask] + val[i + 1]);
    }
  for (ll i = 1; i <= n; i++) res = min(res, f[i][7]);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 8; j++) {
    }
  }
  if (res == MAX) res = -1;
  cout << res;
}
