#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
void solve() {
  long long n, i, j, p;
  cin >> n;
  map<string, long long> mp;
  mp["A"] = INT_MAX;
  mp["B"] = INT_MAX;
  mp["C"] = INT_MAX;
  mp["AB"] = INT_MAX;
  mp["AC"] = INT_MAX;
  mp["BC"] = INT_MAX;
  mp["ABC"] = INT_MAX;
  string s;
  for (i = 0; i < n; i++) {
    cin >> p >> s;
    if ((long long)s.size() == 1) {
      mp[s] = min(mp[s], p);
    } else if ((long long)s.size() == 2) {
      if (s[0] > s[1]) swap(s[0], s[1]);
      mp[s] = min(mp[s], p);
      string s1 = s.substr(0, 1), s2 = s.substr(1, 1);
      mp[s1] = min(mp[s1], p);
      mp[s2] = min(mp[s2], p);
    } else {
      for (auto &x : mp) {
        x.second = min(x.second, p);
      }
    }
  }
  long long ans = INT_MAX;
  ans = min(ans, mp["ABC"]);
  ans = min(ans, mp["A"] + mp["BC"]);
  ans = min(ans, mp["B"] + mp["AC"]);
  ans = min(ans, mp["C"] + mp["AB"]);
  ans = min(ans, mp["A"] + mp["B"] + mp["C"]);
  cout << (ans >= INT_MAX ? -1 : ans) << endl;
}
int main() {
  ;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long T = 1;
  while (T--) {
    solve();
  }
}
