#include <bits/stdc++.h>
using namespace std;
long long t, d, ct, q, ans, l, m, r, n, mx, mn, i, j, k, x, y, z, s;
char ch;
string ss = "", str = "";
map<long long, long long> mp;
set<long long> st;
long long a[200003], b[200003];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  s = k = d = l = mx = m = mn = r = q = i = j = z = x = y = ct = ans = 0;
  cin >> n;
  long long dp[n + 2][8];
  for (i = 0; i <= n; i++)
    for (j = 0; j < 8; j++)
      if (!j)
        dp[i][j] = 0;
      else
        dp[i][j] = 1000000000000000000;
  for (i = 1; i <= n; i++) {
    long long cost;
    cin >> cost >> ss;
    long long msk = 0;
    for (j = 0; j < ss.length(); j++)
      if (ss[j] == 'A')
        msk++;
      else if (ss[j] == 'B')
        msk += 2;
      else
        msk += 4;
    for (j = 0; j < 8; j++) dp[i][j] = dp[i - 1][j];
    for (j = 0; j < 8; j++)
      dp[i][j | msk] = min(dp[i - 1][j] + cost, dp[i][j | msk]);
  }
  if (dp[n][7] == 1000000000000000000)
    cout << -1;
  else
    cout << dp[n][7];
  return 0;
}
