#include <bits/stdc++.h>
using namespace std;
int n, g, a = 100001, b = 100001, c = 100001, ab = 100001, ac = 100001,
          bc = 100001, abc = 100001, u = 300003;
bool ap, bp, cp;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> g >> s;
    ap = false;
    bp = false;
    cp = false;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == 'A') {
        ap = true;
      }
      if (s[j] == 'B') {
        bp = true;
      }
      if (s[j] == 'C') {
        cp = true;
      }
    }
    if (ap == true) {
      a = min(a, g);
      if (bp == true) {
        b = min(b, g);
        ab = min(ab, g);
        if (cp == true) {
          c = min(c, g);
          ac = min(ac, g);
          bc = min(bc, g);
          abc = min(abc, g);
        }
      } else {
        if (cp == true) {
          c = min(c, g);
          ac = min(ac, g);
        }
      }
    } else {
      if (bp == true) {
        b = min(b, g);
        if (cp == true) {
          c = min(c, g);
          bc = min(bc, g);
        }
      } else {
        if (cp == true) {
          c = min(c, g);
        }
      }
    }
  }
  if (a != 100001 && b != 100001 && c != 100001) {
    u = min(u, a + b + c);
  }
  if (a != 100001 && bc != 100001) {
    u = min(u, a + bc);
  }
  if (b != 100001 && ac != 100001) {
    u = min(u, b + ac);
  }
  if (c != 100001 && ab != 100001) {
    u = min(u, c + ab);
  }
  if (abc != 100001) {
    u = min(u, abc);
  }
  if (u == 300003) {
    printf("-1\n");
  } else {
    printf("%d\n", u);
  }
  return 0;
}
