#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long n, i, ans, c;
  string s;
  cin >> n;
  unordered_map<string, long long> m;
  m["A"] = INT_MAX;
  m["B"] = INT_MAX;
  m["C"] = INT_MAX;
  m["AB"] = INT_MAX;
  m["AC"] = INT_MAX;
  m["BC"] = INT_MAX;
  m["ABC"] = INT_MAX;
  for (i = 0; i < n; ++i) {
    cin >> c >> s;
    sort(s.begin(), s.end());
    m[s] = min(c, m[s]);
  }
  ans = min({m["A"] + m["B"] + m["C"], m["ABC"], m["AB"] + m["AC"],
             m["AB"] + m["BC"], m["AC"] + m["BC"], m["A"] + m["BC"],
             m["B"] + m["AC"], m["C"] + m["AB"]});
  if (ans >= INT_MAX)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
