#include <bits/stdc++.h>
using namespace std;
long long int arr[1002][4], n, dp[1002][100];
long long int f(int idx, int mask) {
  if (idx == n && mask == 7) {
    return 0;
  }
  if (idx == n && mask < 7) {
    return 1000000000;
  }
  if (dp[idx][mask] != -1) {
    return dp[idx][mask];
  }
  long long int res = 0;
  int ret = mask;
  for (int j = 1; j <= 3; j++) {
    if (arr[idx][j]) ret |= ((1 << (j - 1)));
  }
  res = arr[idx][0] + f(idx + 1, ret);
  res = min(res, f(idx + 1, mask));
  return dp[idx][mask] = res;
}
int main() {
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) {
    long long int x;
    string s;
    cin >> x >> s;
    arr[i][0] = x;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == 'A') {
        arr[i][1] = 1;
      }
      if (s[j] == 'B') {
        arr[i][2] = 1;
      }
      if (s[j] == 'C') {
        arr[i][3] = 1;
      }
    }
  }
  long long int ans = f(0, 0);
  long long int mnm = LLONG_MAX;
  if (ans >= 1000000000) ans = -1;
  cout << ans << "\n";
}
