#include <bits/stdc++.h>
inline int lowbit(int x) { return x & -x; }
const int N = 1e5 + 10;
const int mod = (int)1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LINF = (1LL << 62);
const double PI = acos(-1.0);
using namespace std;
char buf[100000], *p1 = buf, *p2 = buf;
inline char nc() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline bool read(int &x) {
  char c = nc();
  x = 0;
  if (c == EOF) return false;
  bool flag = false;
  for (; !isdigit(c); c = nc()) flag = true;
  for (; isdigit(c); x = x * 10 + c - '0', c = nc())
    ;
  if (flag) x *= -1;
  return true;
}
inline bool readL(long long &x) {
  char c = nc();
  x = 0;
  if (c == EOF) return false;
  bool flag = false;
  for (; !isdigit(c); c = nc()) flag = true;
  for (; isdigit(c); x = x * 10 + c - '0', c = nc())
    ;
  if (flag) x *= -1;
  return true;
}
struct node {
  int val, typ;
  bool operator<(const node &t) const { return typ < t.typ; }
} v[1005];
int dp[10];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    char ch[10];
    scanf("%d%s", &v[i].val, ch);
    int len = strlen(ch);
    int tmp = 0;
    for (int j = 0; j < len; j++) {
      if (ch[j] == 'A')
        tmp |= 1;
      else if (ch[j] == 'B')
        tmp |= (1 << 1);
      else if (ch[j] == 'C')
        tmp |= (1 << 2);
    }
    v[i].typ = tmp;
  }
  memset(dp, 0x3f, sizeof(dp));
  dp[0] = 0;
  sort(v + 1, v + 1 + n);
  for (int i = 1; i <= n; i++) {
    for (int j = (1 << 3) - 1; j >= 0; j--) {
      dp[j | v[i].typ] = min(dp[j | v[i].typ], dp[j] + v[i].val);
    }
  }
  if (dp[7] == INF)
    printf("-1\n");
  else
    printf("%d\n", dp[7]);
  return 0;
}
