#include <bits/stdc++.h>
using namespace std;
char ch[8];
int val[8], f[4], n, i, j, p, sol;
int main() {
  cin >> n;
  for (i = 1; i <= 7; i++) {
    val[i] = 1000000;
    ch[i] = 0;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= 3; j++) f[j] = 0;
    cin >> p >> ch + 1;
    j = 1;
    while (ch[j] != 0) {
      f[ch[j] - 'A' + 1] = 1;
      j++;
    }
    if (f[1] && f[2] && f[3]) {
      val[7] = min(val[7], p);
      continue;
    }
    if (f[1] && f[2]) {
      val[4] = min(val[4], p);
      continue;
    }
    if (f[1] && f[3]) {
      val[5] = min(val[5], p);
      continue;
    }
    if (f[2] && f[3]) {
      val[6] = min(val[6], p);
      continue;
    }
    if (f[1]) {
      val[1] = min(val[1], p);
      continue;
    }
    if (f[2]) {
      val[2] = min(val[2], p);
      continue;
    }
    if (f[3]) {
      val[3] = min(val[3], p);
      continue;
    }
  }
  sol = 1000000;
  sol = min(sol, val[7]);
  sol = min(sol, val[1] + val[6]);
  sol = min(sol, val[2] + val[5]);
  sol = min(sol, val[3] + val[4]);
  sol = min(sol, val[5] + val[6]);
  sol = min(sol, val[4] + val[6]);
  sol = min(sol, val[4] + val[5]);
  sol = min(sol, val[1] + val[2] + val[3]);
  if (sol != 1000000)
    cout << sol << "\n";
  else
    cout << "-1\n";
  return 0;
}
