#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, k, l = 10000000, x;
  cin >> n;
  map<string, int> m;
  string s1 = "A", s2 = "B", s3 = "C", s4 = "AB", s5 = "BC", s6 = "AC",
         s7 = "ABC", st;
  m[s1] = 10000000;
  m[s2] = 10000000;
  m[s3] = 10000000;
  m[s4] = 10000000;
  m[s5] = 10000000;
  m[s6] = 10000000;
  m[s7] = 10000000;
  for (i = 0; i < n; i++) {
    cin >> x >> st;
    sort(st.begin(), st.end());
    if (st == "A") {
      if (m[st] > x) m[st] = x;
    }
    if (st == "B") {
      if (m[st] > x) m[st] = x;
    }
    if (st == "C") {
      if (m[st] > x) m[st] = x;
    }
    if (st == "AB") {
      if (m[st] > x) m[st] = x;
    }
    if (st == "BC") {
      if (m[st] > x) m[st] = x;
    }
    if (st == "AC") {
      if (m[st] > x) m[st] = x;
    }
    if (st == "ABC") {
      if (m[st] > x) m[st] = x;
    }
  }
  if (l > (m[s1] + m[s2] + m[s3])) l = m[s1] + m[s2] + m[s3];
  if (l > (m[s1] + m[s5])) l = m[s1] + m[s5];
  if (l > (m[s2] + m[s6])) l = m[s2] + m[s6];
  if (l > (m[s3] + m[s4])) l = m[s3] + m[s4];
  if (l > (m[s4] + m[s5])) l = m[s4] + m[s5];
  if (l > (m[s4] + m[s6])) l = m[s4] + m[s6];
  if (l > (m[s5] + m[s6])) l = m[s5] + m[s6];
  if (l > (m[s7])) l = m[s7];
  if (l == 10000000)
    cout << -1 << endl;
  else
    cout << l << endl;
  return 0;
}
