#include <bits/stdc++.h>
using namespace std;
vector<int> cost;
vector<string> vit;
vector<int> dp;
const int inf = 1e9;
inline int getVit(string str) {
  vector<bool> vb = {false, false, false};
  for (int i = 0; i < str.size(); i++) {
    vb[str[i] - 'A'] = true;
  }
  return 1 * vb[0] + 2 * vb[1] + 4 * vb[2];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  cost.resize(n);
  vit.resize(n);
  dp.resize(8, inf);
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    cin >> vit[i];
  }
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 8; j++) {
      int k = getVit(vit[i]);
      dp[j | k] = min(dp[j | k], dp[j] + cost[i]);
    }
  }
  if (dp[7] != inf) {
    cout << dp[7] << endl;
  } else {
    cout << -1 << endl;
  }
}
