#include <bits/stdc++.h>
using namespace std;
int n;
map<string, int> mp;
int main() {
  string vita;
  scanf("%d", &n);
  int c;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c);
    cin >> vita;
    sort(vita.begin(), vita.end());
    if (!mp[vita])
      mp[vita] = c;
    else if (c < mp[vita])
      mp[vita] = c;
  }
  int ans = -1;
  if (mp["ABC"]) {
    if (ans == -1)
      ans = mp["ABC"];
    else
      ans = min(ans, mp["ABC"]);
  }
  if (mp["AB"]) {
    if (mp["AC"]) {
      if (ans == -1)
        ans = mp["AB"] + mp["AC"];
      else
        ans = min(ans, mp["AB"] + mp["AC"]);
    }
    if (mp["BC"]) {
      if (ans == -1)
        ans = mp["AB"] + mp["BC"];
      else
        ans = min(ans, mp["AB"] + mp["BC"]);
    }
    if (mp["C"]) {
      if (ans == -1)
        ans = mp["AB"] + mp["C"];
      else
        ans = min(ans, mp["AB"] + mp["C"]);
    }
  }
  if (mp["AC"]) {
    if (mp["BC"]) {
      if (ans == -1)
        ans = mp["AC"] + mp["BC"];
      else
        ans = min(ans, mp["AC"] + mp["BC"]);
    }
    if (mp["B"]) {
      if (ans == -1)
        ans = mp["AC"] + mp["B"];
      else
        ans = min(ans, mp["AC"] + mp["B"]);
    }
  }
  if (mp["BC"]) {
    if (mp["A"]) {
      if (ans == -1)
        ans = mp["BC"] + mp["A"];
      else
        ans = min(ans, mp["BC"] + mp["A"]);
    }
  }
  if (mp["A"] && mp["B"] && mp["C"]) {
    if (ans == -1)
      ans = mp["A"] + mp["B"] + mp["C"];
    else
      ans = min(ans, mp["A"] + mp["B"] + mp["C"]);
  }
  printf("%d\n", ans);
}
