#include <bits/stdc++.h>
using namespace std;
const int64_t M = 1e3 + 5;
const int64_t inf = 1e8;
int64_t n, dp[M][10], c[M], vitamin[M];
int64_t solve(int64_t idx, int64_t V) {
  if (idx == n) {
    if (V == 7) return 0;
    return inf;
  }
  if (dp[idx][V] != -1) return dp[idx][V];
  int64_t ans =
      min(solve(idx + 1, V | vitamin[idx]) + c[idx], solve(idx + 1, V));
  return dp[idx][V] = ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int64_t i = 0; i < n; i++) {
    cin >> c[i];
    string s;
    cin >> s;
    for (auto ch : s) {
      if (ch == 'A')
        vitamin[i] |= 1;
      else if (ch == 'B')
        vitamin[i] |= 2;
      else
        vitamin[i] |= 4;
    }
  }
  memset(dp, -1, sizeof(dp));
  int64_t ans = solve(0, 0);
  cout << (ans == inf ? -1 : ans) << endl;
  return 0;
}
