#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long base = 331;
const long long non = 1e18 + 7;
const double pi = 3.1415926536;
template <typename type>
inline void read(type& in) {
  bool negative = false;
  char c;
  for (c = getchar(); c<'0' | c> '9'; c = getchar())
    if (c == '-') negative = true;
  in = c - '0';
  for (c = getchar(); c >= '0' && c <= '9'; c = getchar())
    in = in * 10 + c - '0';
  if (negative) in = -in;
}
template <typename type>
inline void write(type out) {
  if (out < 0) {
    putchar('-');
    out = -out;
  }
  type p = 1;
  for (type tmp = out / 10; tmp > 0; tmp /= 10) p *= 10;
  for (; p > 0; out %= p, p /= 10) putchar(out / p + '0');
}
map<string, int> mp;
int n, num, res, a, b, c;
string s, req;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> num;
    cin >> s;
    a = b = c = 0;
    for (int i = 0; i < s.size(); i++)
      if (s[i] == 'A')
        a++;
      else if (s[i] == 'B')
        b++;
      else
        c++;
    req = "";
    if (a) req += 'A';
    if (b) req += 'B';
    if (c) req += 'C';
    if (mp[req])
      mp[req] = min(mp[req], num);
    else
      mp[req] = num;
  }
  res = inf;
  if (mp["ABC"]) res = min(res, mp["ABC"]);
  if (mp["AB"] && mp["C"]) res = min(res, mp["AB"] + mp["C"]);
  if (mp["A"] && mp["BC"]) res = min(res, mp["A"] + mp["BC"]);
  if (mp["B"] && mp["AC"]) res = min(res, mp["B"] + mp["AC"]);
  if (mp["A"] && mp["B"] && mp["C"])
    res = min(res, mp["A"] + mp["B"] + mp["C"]);
  if (mp["AB"] && mp["BC"]) res = min(res, mp["AB"] + mp["BC"]);
  if (mp["BC"] && mp["AC"]) res = min(res, mp["BC"] + mp["AC"]);
  if (mp["AC"] && mp["AB"]) res = min(res, mp["AC"] + mp["AB"]);
  if (res != inf)
    cout << res;
  else
    cout << -1;
}
