#include <bits/stdc++.h>
using namespace std;
int inf = 999999;
int main() {
  int m, n, i, pri, k, a, b, c, ab, ac, bc, abc;
  char s[6];
  a = b = c = ab = ac = bc = abc = inf;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d %s", &pri, s);
    if (strcmp(s, "A") == 0) a = min(a, pri);
    if (strcmp(s, "B") == 0) b = min(b, pri);
    if (strcmp(s, "C") == 0) c = min(c, pri);
    if (strcmp(s, "AB") == 0 || strcmp(s, "BA") == 0) ab = min(ab, pri);
    if (strcmp(s, "AC") == 0 || strcmp(s, "CA") == 0) ac = min(ac, pri);
    if (strcmp(s, "CB") == 0 || strcmp(s, "BC") == 0) bc = min(bc, pri);
    if (strcmp(s, "ABC") == 0 || strcmp(s, "ACB") == 0 ||
        strcmp(s, "BAC") == 0 || strcmp(s, "BCA") == 0 ||
        strcmp(s, "CBA") == 0 || strcmp(s, "CAB") == 0)
      abc = min(abc, pri);
  }
  k = a + b + c;
  k = min(k, abc);
  k = min(k, a + bc);
  k = min(k, b + ac);
  k = min(k, c + ab);
  k = min(k, ab + bc);
  k = min(k, ab + ac);
  k = min(k, ac + bc);
  k = min(k, ab + ac + bc);
  if (k == inf)
    cout << "-1" << endl;
  else
    cout << k << endl;
}
