#include <bits/stdc++.h>
using namespace std;
int n, m;
int dp[100];
string s;
bool t[4];
int main() {
  cin >> n;
  memset(dp, 0x3f, sizeof(dp));
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> m >> s;
    int p = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'A') {
        p += 1;
        t[1] = 1;
      } else if (s[i] == 'B') {
        p += 2;
        t[2] = 1;
      } else if (s[i] == 'C') {
        p += 4;
        t[3] = 1;
      }
    }
    for (int i = 0; i <= 8; i++) {
      dp[i | p] = min(dp[i | p], dp[i] + m);
    }
  }
  if (t[1] == false || t[3] == false || t[2] == false)
    puts("-1");
  else
    cout << dp[7] << endl;
  return 0;
}
