#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
inline void read(int &x) {
  int f = 1;
  x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
inline void readll(long long &x) {
  long long f = 1;
  x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
const int mxstate = (1 << 3) - 1;
const int maxn = 1000 + 5;
int dp[mxstate + 10], n, c[maxn], condition[maxn];
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(c[i]);
    string x;
    cin >> x;
    for (int j = 0; j < x.size(); j++) condition[i] |= (1 << (x[j] - 'A'));
  }
  memset(dp, 0x3f, sizeof(dp));
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int state = 0; state <= mxstate; state++) {
      if (dp[state | condition[i]] > dp[state] + c[i]) {
        dp[state | condition[i]] = dp[state] + c[i];
      }
    }
  }
  if (dp[mxstate] != 0x3f3f3f3f)
    cout << dp[mxstate];
  else
    puts("-1");
  return 0;
}
