#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long t[1000][3] = {0}, c[1000], n;
    vector<long long> v(7, 100005 * 1000);
    cin >> n;
    string s;
    for (long long int i = 0; i < n; i++) {
      cin >> c[i] >> s;
      for (auto x : s) t[i][x - 'A'] = 1;
      if (t[i][0]) {
        v[0] = min(v[0], c[i]);
        if (t[i][1]) {
          v[3] = min(v[3], c[i]);
          v[1] = min(v[1], c[i]);
          if (t[i][2]) {
            v[2] = min(v[2], c[i]);
            v[4] = min(v[4], c[i]);
            v[5] = min(v[5], c[i]);
            v[6] = min(v[6], c[i]);
          }
        }
        if (t[i][2]) {
          v[2] = min(v[2], c[i]);
          v[5] = min(v[5], c[i]);
        }
      } else {
        if (t[i][1]) {
          v[1] = min(v[1], c[i]);
          if (t[i][2]) {
            v[2] = min(v[2], c[i]);
            v[4] = min(v[4], c[i]);
          }
        } else {
          if (t[i][2]) v[2] = min(v[2], c[i]);
        }
      }
    }
    long long ans;
    ans = min(v[6], min(v[0] + v[1] + v[2],
                        min(v[3] + v[2], min(v[4] + v[0], v[5] + v[1]))));
    if (ans >= 100005 * 1000)
      cout << -1;
    else
      cout << ans;
  }
  return 0;
}
