#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 7;
const ll INFF = 1e18 + 7;
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char* x) { cout << '\"' << x << '\"'; }
void __print(const string& x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V>& x) {
  cout << '{';
  __print(x.first);
  cout << ',';
  __print(x.second);
  cout << '}';
}
template <typename T>
void __print(const T& x) {
  int f = 0;
  cout << '{';
  for (auto& i : x) cout << (f++ ? "," : ""), __print(i);
  cout << "}";
}
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cout << ", ";
  _print(v...);
}
void solve() {
  map<string, int> a;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int val;
    string s;
    cin >> val >> s;
    sort(s.begin(), s.end());
    if (!a[s])
      a[s] = val;
    else
      a[s] = min(a[s], val);
  }
  int sum = INF;
  if (a["A"] && a["B"] && a["C"]) sum = min(sum, a["A"] + a["B"] + a["C"]);
  if (a["AB"])
    for (auto i : {"AC", "BC", "C"})
      if (a[i]) sum = min(sum, a["AB"] + a[i]);
  if (a["AC"])
    for (auto i : {"AB", "BC", "B"})
      if (a[i]) sum = min(sum, a["AC"] + a[i]);
  if (a["BC"])
    for (auto i : {"AC", "AB", "A"})
      if (a[i]) sum = min(sum, a["BC"] + a[i]);
  if (a["ABC"]) sum = min(sum, a["ABC"]);
  cout << ((sum == INF) ? -1 : sum) << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  for (int tt = 1; tt <= t; tt++) {
    solve();
  }
  return 0;
}
