#include <bits/stdc++.h>
using namespace std;
int amount;
int price[6005];
char vitamin[6005][5];
int mark[300];
int min_value[300];
void solve() {
  int result = (int)1e9;
  for (int i = 1; i <= amount; i++) {
    int length = strlen(vitamin[i] + 1);
    int now = price[i];
    for (int j = 1; j <= length; j++) mark[vitamin[i][j]] = i;
    for (int j = 'A'; j <= 'C'; j++)
      if (mark[j] != i) now += min_value[j];
    result = min(result, now);
  }
  if (result >= (int)1e9)
    printf("-1");
  else
    printf("%d", result);
}
int main() {
  scanf("%d\n", &amount);
  min_value['A'] = min_value['B'] = min_value['C'] = (int)1e9;
  for (int i = 1; i <= amount; i++) {
    scanf("%d %s\n", &price[i], vitamin[i] + 1);
    int length = strlen(vitamin[i] + 1);
    for (int j = 1; j <= length; j++)
      min_value[vitamin[i][j]] = min(min_value[vitamin[i][j]], price[i]);
  }
  solve();
}
