#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a < b) swap(a, b);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, n, x;
  string s;
  cin >> n;
  long long a = 100000001, b = 100000001, c = 100000001, d = 100000001,
            e = 100000001, f = 100000001, g = 100000001;
  long long k = 0, y = 0, z = 0;
  for (int i = 0; i < n; i++) {
    cin >> x >> s;
    if (s == "A") {
      if (x < a) a = x;
      k = 1;
    } else if (s == "B") {
      if (x < b) b = x;
      y = 1;
    } else if (s == "C") {
      if (x < c) c = x;
      z = 1;
    } else if (s == "AB" || s == "BA") {
      if (x < d) d = x;
      k = 1;
      y = 1;
    } else if (s == "BC" || s == "CB") {
      if (x < e) e = x;
      y = 1;
      z = 1;
    } else if (s == "AC" || s == "CA") {
      if (x < f) f = x;
      k = 1;
      z = 1;
    } else if (s.size() == 3) {
      if (x < g) g = x;
      k = 1;
      y = 1;
      z = 1;
    }
  }
  if (!k || !z || !y)
    cout << -1;
  else
    cout << min(
        min(min(min(min(min(min(a + b + c, d + c), e + a), f + b), g), d + e),
            e + f),
        f + d);
  return 0;
}
