#include <bits/stdc++.h>
using namespace std;
void printans(std::vector<pair<long long, string>> &a) {
  long long n = a.size();
  for (long long i = 0; i < n; i++)
    cout << a[i].first << " " << a[i].second << " \n";
  return;
}
vector<pair<long long, string>> a;
long long n;
void arrayinput() {
  cin >> n;
  a.resize(n);
  for (long long i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
}
long long dp[1001][8];
long long solve(long long i, long long mask) {
  if (i == 0) {
    if (mask == 7)
      return 0;
    else
      return 1000000009;
  }
  if (dp[i][mask] != -1) return dp[i][mask];
  long long newmask = mask;
  for (auto it : a[i - 1].second) {
    if (it == 'A') {
      newmask = newmask | (1 << 2);
    } else if (it == 'B')
      newmask = newmask | (1 << 1);
    else
      newmask = newmask | 1;
  }
  long long c1 = a[i - 1].first + solve(i - 1, newmask);
  long long c2 = solve(i - 1, mask);
  return dp[i][mask] = min(c1, c2);
}
void solveTestCases() {
  arrayinput();
  memset(dp, -1, sizeof(dp));
  long long ans;
  long long mask = 0;
  ans = solve(n, 0);
  if (ans >= 1000000000) ans = -1;
  cout << ans << "\n";
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solveTestCases();
  return 0;
}
