#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 1;
int n, a[10], c, ans;
string s;
int main() {
  cin >> n;
  ans = -1;
  for (int i = 1; i < 10; i++) a[i] = -1;
  for (int i = 0; i < n; i++) {
    cin >> c >> s;
    int bin = 0;
    for (int i = 0; i < s.length(); i++) bin += (1 << (s[i] - 'A'));
    for (int i = 1; i < 8; i++)
      if ((i & bin) == i) {
        if (a[i] == -1)
          a[i] = c;
        else
          a[i] = min(a[i], c);
      }
  }
  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) && a[i] != -1 && a[j] != -1 && a[k] != -1)
          ans = (ans == -1 ? a[i] + a[j] + a[k] : min(ans, a[i] + a[j] + a[k]));
  cout << ans;
}
