#include <bits/stdc++.h>
using namespace std;
int a[1005];
int msk[1005];
int main() {
  int n;
  ignore = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char buf[5];
    ignore = scanf(" %d %s", a + i, buf);
    int m = strlen(buf);
    for (int j = 0; j < m; j++) {
      msk[i] |= (1 << (buf[j] - 'A'));
    }
  }
  int mnA = 10000000, mnB = 10000000, mnC = 10000000;
  for (int i = 0; i < n; i++) {
    if (msk[i] & 1) {
      mnA = min(mnA, a[i]);
    }
    if (msk[i] & 2) {
      mnB = min(mnB, a[i]);
    }
    if (msk[i] & 4) {
      mnC = min(mnC, a[i]);
    }
  }
  if (mnA == 10000000 || mnB == 10000000 || mnC == 10000000) {
    printf("-1");
    return 0;
  }
  int ans = mnA + mnB + mnC;
  for (int i = 0; i < n; i++) {
    if (msk[i] == 7) {
      ans = min(ans, a[i]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if ((msk[i] | msk[j]) == 7) {
        ans = min(ans, a[i] + a[j]);
      }
    }
  }
  printf("%d", ans);
}
