#include <bits/stdc++.h>
using namespace std;
vector<int> v(100001);
int c[100001];
int a[100001];
void solve() {
  map<string, int> mp;
  int n;
  cin >> n;
  int ok[4] = {0};
  vector<string> s = {"A", "B", "C", "AB", "AC", "BC", "ABC"};
  for (int i = 0; i < n; i++) {
    int x;
    string a;
    cin >> x >> a;
    sort(a.begin(), a.end());
    for (auto j : a) ok[j - 'A'] = 1;
    for (int j = 0; j < s.size(); j++) {
      int ch = 0;
      for (int k = 0; k < a.length(); k++) {
        for (int r = 0; r < s[j].length(); r++) {
          if (a[k] == s[j][r]) ch++;
        }
      }
      if (ch == s[j].length()) {
        if (mp.find(s[j]) != mp.end()) {
          mp[s[j]] = min(mp[s[j]], x);
        } else {
          mp[s[j]] = x;
        }
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    if (ok[i] == 0) {
      cout << "-1\n";
      return;
    }
  }
  int ans = INT_MAX;
  vector<vector<string>> v = {
      {"A", "BC"}, {"A", "B", "C"}, {"AB", "C"}, {"AC", "B"}, {"ABC"}};
  for (int i = 0; i < v.size(); i++) {
    int cur = 0, ch = 0;
    for (int j = 0; j < v[i].size(); j++) {
      if (mp.find(v[i][j]) == mp.end()) {
        ch = 1;
        break;
      }
      cur += mp[v[i][j]];
    }
    if (ch == 1) continue;
    ans = min(ans, cur);
  }
  cout << ans << "\n";
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
