#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 7;
int c[maxn];
string s[maxn];
int dp[maxn][10];
map<char, int> mp;
int main() {
  int n;
  mp['A'] = 1;
  mp['B'] = 2;
  mp['C'] = 4;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i] >> s[i];
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    int temp = 0;
    for (auto it : s[i]) temp += mp[it];
    for (int j = 0; j < 8; j++) {
      if (dp[i - 1][j] != -1) {
        if (dp[i][j | temp] == -1)
          dp[i][j | temp] = dp[i - 1][j] + c[i];
        else
          dp[i][j | temp] = min(dp[i][j | temp], dp[i - 1][j] + c[i]);
        if (dp[i][j] == -1)
          dp[i][j] = dp[i - 1][j];
        else
          dp[i][j] = min(dp[i - 1][j], dp[i][j]);
      }
    }
  }
  cout << dp[n][7] << endl;
  return 0;
}
