#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arrp[n];
  string s;
  int a = 300001, b = 300001, c = 300001, ab = 300001, ac = 300001, bc = 300001,
      abc = 300001, noa = 0, nob = 0, noc = 0;
  for (int i = 0; i < n; i++) {
    cin >> arrp[i];
    cin >> s;
    if (s.size() == 1) {
      if (s[0] == 'A' && arrp[i] < a) {
        a = arrp[i];
        noa++;
      } else if (s[0] == 'B' && arrp[i] < b) {
        b = arrp[i];
        nob++;
      } else if (s[0] == 'C' && arrp[i] < c) {
        c = arrp[i];
        noc++;
      }
    } else if (s.size() == 2) {
      if ((s == "AB" || s == "BA") && arrp[i] < ab) {
        ab = arrp[i];
        noa++;
        nob++;
      } else if ((s == "BC" || s == "CB") && arrp[i] < bc) {
        bc = arrp[i];
        nob++;
        noc++;
      } else if ((s == "CA" || s == "AC") && arrp[i] < ac) {
        ac = arrp[i];
        noa++;
        noc++;
      }
    } else {
      if (arrp[i] < abc) {
        abc = arrp[i];
        noa++;
        nob++;
        noc++;
      }
    }
  }
  int arr[8];
  arr[0] = (a + b + c);
  arr[1] = (a + bc);
  arr[2] = (b + ac);
  arr[3] = (c + ab);
  arr[4] = (abc);
  arr[5] = (ab + bc);
  arr[6] = (ab + ac);
  arr[7] = (bc + ac);
  sort(arr, arr + 8);
  if (noa == 0 || nob == 0 || noc == 0) {
    cout << "-1" << endl;
  } else {
    cout << arr[0] << endl;
  }
  return 0;
}
