#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
  Finish_read = 0;
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x *= f;
  Finish_read = 1;
}
template <class T>
inline void print(T x) {
  if (x / 10 != 0) print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void writeln(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
  putchar('\n');
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
}
int n, v[8];
char s[5];
int main() {
  for (int i = 0; i < 8; ++i) v[i] = 1e8;
  v[0] = 0;
  read(n);
  for (int i = 1, x; i <= n; ++i) {
    read(x), scanf("%s", s + 1);
    int l = strlen(s + 1), res = 0;
    for (int j = 1; j <= l; ++j) res |= 1 << (s[j] - 'A');
    v[res] = min(v[res], x);
  }
  int ans = 2e9;
  for (int i = 0; i < 8; ++i)
    for (int j = 0; j < 8; ++j)
      for (int k = 0; k < 8; ++k)
        if ((i | j | k) == 7) ans = min(ans, v[i] + v[j] + v[k]);
  if (ans > 1e7)
    cout << "-1" << endl;
  else
    cout << ans << endl;
}
