#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int mod = 1000000007;
int n, preco[N];
int dp[N][10];
string vit[N];
bool comp(string s, char x) {
  for (int i = 0; i < (int)(s).size(); i++)
    if (s[i] == x) return true;
  return false;
}
int solve(int pos, int bitmask) {
  if (bitmask == 7) return 0;
  if (pos == n) return 0x3f3f3f3f;
  int &ans = dp[pos][bitmask];
  if (ans != -1) return ans;
  ans = solve(pos + 1, bitmask);
  int mask = 0;
  if (comp(vit[pos], 'A')) mask |= 1;
  if (comp(vit[pos], 'B')) mask |= 2;
  if (comp(vit[pos], 'C')) mask |= 4;
  ans = min(ans, solve(pos + 1, mask | bitmask) + preco[pos]);
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> preco[i] >> vit[i];
  }
  memset(dp, -1, sizeof(dp));
  int ans = solve(0, 0);
  if (ans < 0x3f3f3f3f)
    cout << ans << "\n";
  else
    cout << -1 << "\n";
  return 0;
}
