#include <bits/stdc++.h>
using namespace std;
void print_pair(pair<int, int> a) {
  cerr << "(" << a.first << ", " << a.second << ") ";
}
template <int T1, int T2>
void print_2d(int a[T1][T2], int x, int y) {
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      cerr << a[i][j] << " ";
    }
    cerr << endl;
  }
}
template <class T>
void print_array(T a[], size_t n) {
  cerr << "array:";
  for (int i = 0; i < n - 1; i++) cerr << a[i] << ",";
  cerr << a[n - 1] << endl;
}
long long dp[2][2][2];
long long n, c[1000];
int main() {
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      for (int k = 0; k < 2; k++) dp[i][j][k] = LLONG_MAX;
  dp[0][0][0] = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long tmp1;
    string tmp2;
    cin >> tmp1 >> tmp2;
    long long a = tmp2.find('A') != string::npos ? 2 : 1;
    long long b = tmp2.find('B') != string::npos ? 2 : 1;
    long long c = tmp2.find('C') != string::npos ? 2 : 1;
    for (int i = 0; i < a; i++)
      for (int j = 0; j < b; j++)
        for (int k = 0; k < c; k++) {
          dp[i][j][k] = min(dp[i][j][k], tmp1);
        }
  }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      for (int k = 0; k < 2; k++)
        for (int l = 0; l < 2; l++)
          for (int m = 0; m < 2; m++)
            for (int o = 0; o < 2; o++) {
              if (dp[l][m][o] == LLONG_MAX || dp[i][j][k] == LLONG_MAX)
                continue;
              dp[i | l][j | m][k | o] =
                  min(dp[i | l][j | m][k | o], dp[i][j][k] + dp[l][m][o]);
            }
  if (dp[1][1][1] == LLONG_MAX)
    cout << -1 << endl;
  else
    cout << dp[1][1][1] << endl;
  return 0;
}
