#include <bits/stdc++.h>
int main() {
  int n, v, a, b, c, ab, ac, bc, abc, ans;
  char s[10] = {};
  a = b = c = ab = ac = bc = abc = 0x7FFFFFFF;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %s", &v, s);
    if (strcmp(s, "A") == 0)
      a = a > v ? v : a;
    else if (strcmp(s, "B") == 0)
      b = b > v ? v : b;
    else if (strcmp(s, "C") == 0)
      c = c > v ? v : c;
    else if (strcmp(s, "AB") == 0 || strcmp(s, "BA") == 0)
      ab = ab > v ? v : ab;
    else if (strcmp(s, "AC") == 0 || strcmp(s, "CA") == 0)
      ac = ac > v ? v : ac;
    else if (strcmp(s, "BC") == 0 || strcmp(s, "CB") == 0)
      bc = bc > v ? v : bc;
    else
      abc = abc > v ? v : abc;
  }
  ans = 0x7FFFFFFF;
  if (a != 0x7FFFFFFF && b != 0x7FFFFFFF && c != 0x7FFFFFFF)
    ans = ans > a + b + c ? a + b + c : ans;
  if (a != 0x7FFFFFFF && bc != 0x7FFFFFFF) ans = ans > a + bc ? a + bc : ans;
  if (ab != 0x7FFFFFFF && c != 0x7FFFFFFF) ans = ans > ab + c ? ab + c : ans;
  if (ac != 0x7FFFFFFF && b != 0x7FFFFFFF) ans = ans > ac + b ? ac + b : ans;
  if (ab != 0x7FFFFFFF && bc != 0x7FFFFFFF) ans = ans > ab + bc ? ab + bc : ans;
  if (ab != 0x7FFFFFFF && ac != 0x7FFFFFFF) ans = ans > ab + ac ? ab + ac : ans;
  if (ac != 0x7FFFFFFF && bc != 0x7FFFFFFF) ans = ans > ac + bc ? ac + bc : ans;
  if (abc != 0x7FFFFFFF) ans = ans > abc ? abc : ans;
  if (ans == 0x7FFFFFFF) ans = -1;
  printf("%d\n", ans);
  return 0;
}
