#include <bits/stdc++.h>
using namespace std;
bool A[69420];
int main() {
  int n;
  cin >> n;
  int arr[] = {696969, 696969, 696969, 696969, 696969, 696969, 696969};
  bool flaga = 0, flagb = 0, flagc = 0;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    string v;
    cin >> v;
    int A = count(v.begin(), v.end(), 'A');
    if (A) flaga = 1;
    int B = count(v.begin(), v.end(), 'B');
    if (B) flagb = 1;
    int C = count(v.begin(), v.end(), 'C');
    if (C) flagc = 1;
    if (A && B && C)
      arr[6] = min(arr[6], p);
    else if (A && C)
      arr[5] = min(arr[5], p);
    else if (B && C)
      arr[4] = min(arr[4], p);
    else if (A && B)
      arr[3] = min(arr[3], p);
    else if (C)
      arr[2] = min(arr[2], p);
    else if (B)
      arr[1] = min(arr[1], p);
    else
      arr[0] = min(arr[0], p);
  }
  if (!flaga || !flagb || !flagc) {
    cout << -1;
    return 0;
  }
  cout << min({arr[0] + arr[1] + arr[2], arr[3] + arr[2], arr[4] + arr[0],
               arr[5] + arr[1], arr[6], arr[3] + arr[4], arr[4] + arr[5],
               arr[3] + arr[5]});
  return 0;
}
