#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; i++) {
    int p;
    string s;
    cin >> p >> s;
    sort(s.begin(), s.end());
    if (mp.find(s) == mp.end())
      mp[s] = p;
    else {
      if (mp[s] > p) mp[s] = p;
    }
  }
  int p1 = INT_MAX, p2 = INT_MAX, p3 = INT_MAX;
  int ans = INT_MAX;
  if (mp.find("A") != mp.end()) {
    int ans1 = INT_MAX;
    if (mp.find("BC") != mp.end()) {
      p1 = mp["A"] + mp["BC"];
      ans1 = min(ans1, p1);
    }
    if ((mp.find("B") != mp.end()) && (mp.find("C") != mp.end())) {
      p2 = mp["A"] + mp["B"] + mp["C"];
      ans1 = min(ans1, p2);
    }
    if (mp.find("ABC") != mp.end()) {
      p3 = mp["A"] + mp["ABC"];
      ans1 = min(ans1, p3);
    }
    ans = min(ans1, ans);
  }
  if (mp.find("B") != mp.end()) {
    int ans1 = INT_MAX;
    if (mp.find("AC") != mp.end()) {
      p1 = mp["B"] + mp["AC"];
      ans1 = min(ans1, p1);
    }
    if ((mp.find("A") != mp.end()) && (mp.find("C") != mp.end())) {
      p2 = mp["A"] + mp["B"] + mp["C"];
      ans1 = min(ans1, p2);
    }
    if (mp.find("ABC") != mp.end()) {
      p3 = mp["B"] + mp["ABC"];
      ans1 = min(ans1, p3);
    }
    ans = min(ans, ans1);
  }
  if (mp.find("C") != mp.end()) {
    int ans1 = INT_MAX;
    if (mp.find("AB") != mp.end()) {
      p1 = mp["C"] + mp["AB"];
      ans1 = min(ans, p1);
    }
    if ((mp.find("A") != mp.end()) && (mp.find("B") != mp.end())) {
      p2 = mp["A"] + mp["B"] + mp["C"];
      ans1 = min(ans1, p2);
    }
    if (mp.find("ABC") != mp.end()) {
      p3 = mp["C"] + mp["ABC"];
      ans1 = min(ans1, p3);
    }
    ans = min(ans, ans1);
  }
  if (mp.find("AB") != mp.end()) {
    int ans1 = INT_MAX;
    if (mp.find("AC") != mp.end()) {
      p1 = mp["AB"] + mp["AC"];
      ans1 = min(ans1, p1);
    }
    if (mp.find("BC") != mp.end()) {
      p2 = mp["AB"] + mp["BC"];
      ans1 = min(ans1, p2);
    }
    if (mp.find("ABC") != mp.end()) {
      p3 = mp["AB"] + mp["ABC"];
      ans1 = min(ans1, p3);
    }
    ans = min(ans, ans1);
  }
  if (mp.find("BC") != mp.end()) {
    int ans1 = INT_MAX;
    if (mp.find("AC") != mp.end()) {
      p1 = mp["BC"] + mp["AC"];
      ans1 = min(ans1, p1);
    }
    if (mp.find("AB") != mp.end()) {
      p2 = mp["AB"] + mp["BC"];
      ans1 = min(ans1, p2);
    }
    if (mp.find("ABC") != mp.end()) {
      p3 = mp["BC"] + mp["ABC"];
      ans1 = min(ans1, p3);
    }
    ans = min(ans, ans1);
  }
  if (mp.find("AC") != mp.end()) {
    int ans1 = INT_MAX;
    if (mp.find("AB") != mp.end()) {
      p1 = mp["AB"] + mp["AC"];
      ans1 = min(ans1, p1);
    }
    if (mp.find("BC") != mp.end()) {
      p2 = mp["AC"] + mp["BC"];
      ans1 = min(ans1, p2);
    }
    if (mp.find("ABC") != mp.end()) {
      p3 = mp["AC"] + mp["ABC"];
      ans1 = min(ans1, p3);
    }
    ans = min(ans, ans1);
  }
  if (mp.find("ABC") != mp.end()) ans = min(ans, mp["ABC"]);
  if (ans == INT_MAX)
    cout << -1;
  else
    cout << ans;
}
