#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  map<string, long long> m;
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    string y;
    cin >> x >> y;
    sort(y.begin(), y.end());
    if (m[y] == 0)
      m[y] = x;
    else
      m[y] = min(m[y], x);
  }
  long long ans = INT_MAX;
  for (auto it = m.begin(); it != m.end(); it++) {
    for (auto i = m.begin(); i != m.end(); i++) {
      if (i == it) continue;
      string s1 = it->first;
      string s2 = i->first;
      set<char> s;
      for (long long p = 0; p < s1.size(); p++) s.insert(s1[p]);
      for (long long q = 0; q < s2.size(); q++) s.insert(s2[q]);
      if (s.size() == 3) ans = min(ans, m[s1] + m[s2]);
    }
  }
  if (m["ABC"] > 0) ans = min(ans, m["ABC"]);
  if (m["A"] > 0 && m["B"] > 0 && m["C"] > 0)
    ans = min(ans, m["A"] + m["B"] + m["C"]);
  if (ans != INT_MAX)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
