#include <bits/stdc++.h>
using namespace std;
int n;
char s[10];
int c[1 << 5];
int qs() {
  int n = strlen(s + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'A') ans += 1;
    if (s[i] == 'B') ans += 2;
    if (s[i] == 'C') ans += 4;
  }
  return ans;
}
int main() {
  for (int i = 0; i < 1 << 3; i++) c[i] = 1 << 20;
  c[0] = 0;
  scanf("%d", &n);
  getchar();
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    scanf("%s", s + 1);
    int t = qs();
    c[t] = min(c[t], k);
  }
  int ans = 1e6;
  for (int i = 0; i < 1 << 3; i++)
    for (int j = 0; j < 1 << 3; j++)
      for (int k = 0; k < 1 << 3; k++) {
        int t = (i | j) | k;
        if (t == ((1 << 3) - 1)) ans = min(ans, c[i] + c[j] + c[k]);
      }
  if (ans == 1e6)
    printf("-1");
  else
    printf("%d", ans);
}
