#include <bits/stdc++.h>
using namespace std;
long long i, j, k;
long long min(long long a, long long b) { return a < b ? a : b; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<pair<int, string>> v;
  long long a = INT_MAX, b, c, ab, bc, ac, abc;
  b = c = ab = ac = bc = abc = a;
  for (i = 0; i < n; i++) {
    int h;
    string s;
    cin >> h >> s;
    v.push_back(make_pair(h, s));
  }
  int w1, w2, w3;
  w1 = w2 = w3 = 0;
  for (int i = 0; i < n; i++) {
    if (v[i].second == "A") {
      a = min(a, v[i].first);
      w1 = 1;
    }
    if (v[i].second == "B") {
      w2 = 1;
      b = min(b, v[i].first);
    }
    if (v[i].second == "C") {
      w3 = 1;
      c = min(c, v[i].first);
    }
    if (v[i].second == "AB" || v[i].second == "BA") {
      w1 = w2 = 1;
      ab = min(ab, v[i].first);
    }
    if (v[i].second == "BC" || v[i].second == "CB") {
      w3 = w2 = 1;
      bc = min(bc, v[i].first);
    }
    if (v[i].second == "AC" || v[i].second == "CA") {
      w1 = w3 = 1;
      ac = min(ac, v[i].first);
    }
    if (v[i].second == "ABC" || v[i].second == "ACB" || v[i].second == "BCA" ||
        v[i].second == "BAC" || v[i].second == "CAB" || v[i].second == "CBA") {
      w1 = w2 = w3 = 1;
      abc = min(abc, v[i].first);
    }
  }
  if (w1 == 0 || w2 == 0 || w3 == 0) {
    cout << "-1";
    return 0;
  }
  long long mini = abc;
  if (bc + a < mini) mini = bc + a;
  if (ab + c < mini) mini = ab + c;
  if (ac + b < mini) mini = ac + b;
  if (a + b + c < mini) mini = a + b + c;
  if (ab + bc < mini) mini = ab + bc;
  if (bc + ac < mini) mini = bc + ac;
  if (ab + ac < mini) mini = ab + ac;
  cout << mini;
}
