#include <bits/stdc++.h>
using namespace std;
const int _ = 1005;
int n, x, t[_][3];
int main() {
  scanf("%d", &n);
  char s[10];
  int s1 = 4e5, s2 = 4e5, s3 = 4e5, s4 = 4e5, s5 = 4e5, s6 = 4e5, s7 = 4e5;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x);
    scanf("%s", s + 1);
    int m = strlen(s + 1);
    for (int j = 1; j <= m; ++j) {
      if (s[j] == 'A')
        t[i][0] = 1;
      else if (s[j] == 'B')
        t[i][1] = 1;
      else
        t[i][2] = 1;
    }
    if (t[i][0] && m == 1) s1 = min(s1, x);
    if (t[i][1] && m == 1) s2 = min(s2, x);
    if (t[i][2] && m == 1) s3 = min(s3, x);
    if (t[i][0] && t[i][1] && m == 2) s4 = min(s4, x);
    if (t[i][0] && t[i][2] && m == 2) s5 = min(s5, x);
    if (t[i][1] && t[i][2] && m == 2) s6 = min(s6, x);
    if (t[i][0] && t[i][1] && t[i][2] && m == 3) s7 = min(s7, x);
  }
  int ans = 4e5;
  ans = min(ans, s7);
  ans = min(ans, min(s6 + s1, min(s6 + s4, s6 + s5)));
  ans = min(ans, min(s5 + s2, min(s5 + s4, s5 + s6)));
  ans = min(ans, min(s4 + s3, min(s4 + s5, s4 + s6)));
  ans = min(ans, s1 + s2 + s3);
  if (ans == 4e5)
    puts("-1");
  else
    cout << ans << endl;
  return 0;
}
