#include <bits/stdc++.h>
using namespace std;
int n, c;
int dp[8];
char s[3];
int main() {
  scanf("%d", &n);
  for (int i = 1; i < 8; ++i) dp[i] = 1e9;
  for (int k = 1; k <= n; ++k) {
    scanf("%d%s", &c, s);
    int status = 0;
    int len = strlen(s);
    for (int i = 0; i < len; ++i) status |= 1 << (s[i] - 'A');
    for (int i = 0; i < 8; ++i) dp[i | status] = min(dp[i | status], dp[i] + c);
  }
  printf("%d\n", dp[7] == 1e9 ? -1 : dp[7]);
  return 0;
}
