#include <bits/stdc++.h>
using namespace std;
int n, c[1005], need[8];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 7; i++) need[i] = 100000000;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
    string s;
    cin >> s;
    if (s.length() == 1) {
      if (s[0] == 'A') need[1] = min(need[1], c[i]);
      if (s[0] == 'B') need[2] = min(need[2], c[i]);
      if (s[0] == 'C') need[3] = min(need[3], c[i]);
    } else if (s.length() == 2) {
      if ((s[0] == 'A' && s[1] == 'B') || (s[0] == 'B' && s[1] == 'A'))
        need[4] = min(need[4], c[i]);
      if ((s[0] == 'C' && s[1] == 'B') || (s[0] == 'B' && s[1] == 'C'))
        need[6] = min(need[6], c[i]);
      if ((s[0] == 'A' && s[1] == 'C') || (s[0] == 'C' && s[1] == 'A'))
        need[5] = min(need[5], c[i]);
    } else
      need[7] = min(need[7], c[i]);
  }
  int ans = 100000000;
  ans = min(ans, need[1] + need[2] + need[3]);
  ans = min(ans, need[1] + need[6]);
  ans = min(ans, need[2] + need[5]);
  ans = min(ans, need[3] + need[4]);
  ans = min(ans, need[7]);
  ans = min(ans, need[4] + need[5]);
  ans = min(ans, need[5] + need[6]);
  ans = min(ans, need[4] + need[6]);
  if (ans == 100000000)
    printf("-1\n");
  else
    printf("%d\n", ans);
}
