#include <bits/stdc++.h>
using namespace std;
int max1 = 300010;
int dp[4][4];
int main() {
  int n;
  string s;
  int i, j;
  int price;
  for (i = 1; i <= 3; i++)
    for (j = 1; j <= 3; j++) dp[i][j] = max1;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> price >> s;
    if (s.size() == 1) {
      if (s[0] == 'A') {
        if (dp[1][1] > price) dp[1][1] = price;
      } else if (s[0] == 'B') {
        if (dp[1][2] > price) dp[1][2] = price;
      } else {
        if (dp[1][3] > price) dp[1][3] = price;
      }
    } else if (s.size() == 2) {
      int x = 0, y = 0, z = 0;
      for (j = 0; j < 2; j++) {
        if (s[j] == 'A')
          x = 1;
        else if (s[j] == 'B')
          y = 1;
        else
          z = 1;
      }
      if (x == y == 1) {
        if (dp[2][1] > price) dp[2][1] = price;
      } else if (x == z == 1) {
        if (dp[2][2] > price) dp[2][2] = price;
      } else {
        if (dp[2][3] > price) dp[2][3] = price;
      }
    } else {
      if (dp[3][1] > price) dp[3][1] = price;
    }
  }
  if (dp[1][1] + dp[1][2] + dp[1][3] < dp[3][1])
    dp[3][1] = dp[1][1] + dp[1][2] + dp[1][3];
  if (dp[1][1] + dp[2][3] < dp[3][1]) dp[3][1] = dp[1][1] + dp[2][3];
  if (dp[1][2] + dp[2][2] < dp[3][1]) dp[3][1] = dp[1][2] + dp[2][2];
  if (dp[1][3] + dp[2][1] < dp[3][1]) dp[3][1] = dp[1][3] + dp[2][1];
  if (dp[2][1] + dp[2][2] < dp[3][1]) dp[3][1] = dp[2][1] + dp[2][2];
  if (dp[2][2] + dp[2][3] < dp[3][1]) dp[3][1] = dp[2][2] + dp[2][3];
  if (dp[2][1] + dp[2][3] < dp[3][1]) dp[3][1] = dp[2][1] + dp[2][3];
  if (dp[3][1] == max1)
    cout << -1 << endl;
  else
    cout << dp[3][1] << endl;
  return 0;
}
