#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
int n, p[1002], w[1002];
char st[10];
int dp[10];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    w[i] = 0;
    scanf("%s", st);
    for (int j = 0; st[j] != '\0'; j++)
      if (st[j] == 'A')
        w[i] += 1;
      else if (st[j] == 'B')
        w[i] += 2;
      else
        w[i] += 4;
  }
  for (int i = 1; i <= 7; i++) dp[i] = 1000000;
  dp[0] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 7; j++)
      if ((dp[j | w[i]] > dp[j] + p[i]) && (dp[j] != 1000000))
        dp[j | w[i]] = dp[j] + p[i];
  if (dp[7] == 1000000)
    printf("-1");
  else
    printf("%d", dp[7]);
}
