#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int maxn = 3e5 + 5;
char s[5];
struct node {
  bool a, b, c;
  int v;
  bool operator<(const node& nd) const { return v < nd.v; }
};
node nd[1005];
int main() {
  int n;
  scanf("%d", &n);
  int mia = 0x3f3f3f3f;
  int mib = 0x3f3f3f3f;
  int mic = 0x3f3f3f3f;
  int ans = 0x3f3f3f3f;
  for (int i = 0; i < n; i++) {
    scanf("%d", &nd[i].v);
    scanf("%s", s);
    nd[i].a = false;
    nd[i].b = false;
    nd[i].c = false;
    int len = strlen(s);
    for (int j = 0; j < len; j++) {
      if (s[j] == 'A') {
        nd[i].a = true;
        mia = min(mia, nd[i].v);
      } else if (s[j] == 'B') {
        nd[i].b = true;
        mib = min(mib, nd[i].v);
      } else {
        nd[i].c = true;
        mic = min(mic, nd[i].v);
      }
    }
    if (nd[i].a && nd[i].b && nd[i].c) ans = min(nd[i].v, ans);
  }
  if (mia == 0x3f3f3f3f || mib == 0x3f3f3f3f || mic == 0x3f3f3f3f) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int cst = nd[i].v + nd[j].v;
      bool aa = (nd[i].a | nd[j].a);
      bool bb = (nd[i].b | nd[j].b);
      bool cc = (nd[i].c | nd[j].c);
      if (!aa) cst += mia;
      if (!bb) cst += mib;
      if (!cc) cst += mic;
      ans = min(ans, cst);
    }
  }
  printf("%d\n", (ans));
  return 0;
}
