#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
map<string, long long> mp;
int main() {
  int n;
  cin >> n;
  mp["A"] = INF;
  mp["B"] = INF;
  mp["C"] = INF;
  mp["AB"] = INF;
  mp["AC"] = INF;
  mp["BC"] = INF;
  mp["ABC"] = INF;
  for (int i = 0; i < n; i++) {
    long long num;
    string str;
    cin >> num >> str;
    sort(str.begin(), str.end());
    mp[str] = min(mp[str], num);
  }
  long long ans = INF;
  ans = min(ans,
            min(mp["A"] + mp["B"] + mp["C"],
                min(mp["AB"] + mp["C"],
                    min(mp["AC"] + mp["B"],
                        min(mp["BC"] + mp["A"],
                            min(mp["ABC"], min(mp["AB"] + mp["AC"],
                                               min(mp["AC"] + mp["BC"],
                                                   mp["AB"] + mp["BC"]))))))));
  if (ans == INF)
    cout << "-1" << endl;
  else
    cout << ans << endl;
  return 0;
}
