#include <bits/stdc++.h>
using namespace std;
const int inf = numeric_limits<int>::max();
const long long linf = numeric_limits<long long>::max();
const int max_n = 1001;
int n, cost[max_n], best[8];
map<char, int> m = {{'A', 1}, {'B', 2}, {'C', 4}};
int v(string s) {
  int vits = 0;
  for (char c : s) {
    vits |= m[c];
  }
  return vits;
}
int main() {
  scanf("%d", &n);
  string s;
  int vits, c;
  for (int i = 0; i < (8); ++i) {
    best[i] = inf;
  }
  for (int i = 0; i < (n); ++i) {
    cin >> cost[i];
    cin >> s;
    vits = v(s);
    best[vits] = min(best[vits], cost[i]);
  }
  c = inf;
  best[0] = 0;
  for (int i = 0; i < (8); ++i) {
    for (int j = 0; j < (8); ++j) {
      for (int k = 0; k < (8); ++k) {
        if ((i | j | k) == 7 && best[i] != inf && best[j] != inf &&
            best[k] != inf) {
          c = min(c, best[i] + best[j] + best[k]);
        }
      }
    }
  }
  cout << ((c == inf) ? -1 : c) << endl;
  return 0;
}
