#include <bits/stdc++.h>
const int N = 2e5 + 7;
using namespace std;
inline int read() {
  int X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
struct node {
  int val;
  int tag[10];
} node[N];
char s[N];
const int inf = 0x3f3f3f3f;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &node[i].val);
    scanf("%s", s);
    int len = strlen(s);
    for (int j = 0; j < len; j++) {
      if (s[j] == 'A')
        node[i].tag[1] = 1;
      else if (s[j] == 'B')
        node[i].tag[2] = 1;
      else if (s[j] == 'C')
        node[i].tag[3] = 1;
    }
  }
  int mi_A = inf, mi_B = inf, mi_C = inf, mi_AB = inf, mi_AC = inf, mi_BC = inf,
      mi_ABC = inf;
  for (int i = 1; i <= n; i++) {
    if (node[i].tag[1]) {
      mi_A = min(mi_A, node[i].val);
    }
    if (node[i].tag[2]) {
      mi_B = min(mi_B, node[i].val);
    }
    if (node[i].tag[3]) {
      mi_C = min(mi_C, node[i].val);
    }
    if (node[i].tag[1]) {
      mi_A = min(mi_A, node[i].val);
    }
    if (node[i].tag[1] && node[i].tag[2]) {
      mi_AB = min(mi_AB, node[i].val);
    }
    if (node[i].tag[1] && node[i].tag[3]) {
      mi_AC = min(mi_AC, node[i].val);
    }
    if (node[i].tag[2] && node[i].tag[3]) {
      mi_BC = min(mi_BC, node[i].val);
    }
    if (node[i].tag[1] && node[i].tag[2] && node[i].tag[3]) {
      mi_ABC = min(mi_ABC, node[i].val);
    }
  }
  int ans = inf;
  ans = min(ans, mi_A + mi_BC);
  ans = min(ans, mi_B + mi_AC);
  ans = min(ans, mi_C + mi_AB);
  ans = min(ans, mi_ABC);
  ans = min(ans, mi_A + mi_C + mi_B);
  ans = min(ans, mi_AB + mi_AC);
  ans = min(ans, mi_AB + mi_BC);
  ans = min(ans, mi_AC + mi_BC);
  ans = min(ans, mi_AC + mi_AB);
  ans = min(ans, mi_BC + mi_AB);
  ans = min(ans, mi_BC + mi_AC);
  if (ans == inf)
    puts("-1");
  else
    printf("%d\n", ans);
  return 0;
}
