#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 5;
const long long mod = 1e9 + 7;
int num[10];
int nape[maxn];
char str[10];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, d, S = 0, len, m = 0;
  for (int i = 0; i <= 7; i++) num[i] = mod;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %s", &d, str);
    S = 0;
    len = strlen(str);
    for (int j = 0; j < len; j++) {
      if (str[j] == 'A') S = (S | 1);
      if (str[j] == 'B') S = (S | (1 << 1));
      if (str[j] == 'C') S = (S | (1 << 2));
    }
    if (d < num[S]) num[S] = d;
  }
  int ans = -1;
  if (num[1] != mod && num[6] != mod) {
    m++;
    nape[m] = num[1] + num[6];
  }
  if (num[1] != mod && num[2] != mod && num[4] != mod) {
    m++;
    nape[m] = num[1] + num[2] + num[4];
  }
  if (num[2] != mod && num[5] != mod) {
    m++;
    nape[m] = num[2] + num[5];
  }
  if (num[4] != mod && num[3] != mod) {
    m++;
    nape[m] = num[3] + num[4];
  }
  if (num[3] != mod && num[6] != mod) {
    m++;
    nape[m] = num[3] + num[6];
  }
  if (num[3] != mod && num[5] != mod) {
    m++;
    nape[m] = num[3] + num[5];
  }
  if (num[5] != mod && num[6] != mod) {
    m++;
    nape[m] = num[5] + num[6];
  }
  if (num[7] != mod) {
    m++;
    nape[m] = num[7];
  }
  if (m == 0)
    cout << "-1" << endl;
  else {
    sort(nape + 1, nape + m + 1);
    cout << nape[1] << endl;
  }
  return 0;
}
