#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
void print(long long* a, long long n) {
  long long i;
  for (i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
void fio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
double func(double x) { return 2 * x * x - 12 * x + 7; }
double ts(double start, double end) {
  double l = start, r = end;
  for (long long i = 0; i < 200; i++) {
    double l1 = l + (r - l) / 3;
    double l2 = r - (r - l) / 3;
    if (func(l1) < func(l2))
      r = l2;
    else
      l = l1;
  }
  double x = l;
  return func(x);
}
int32_t main() {
  fio();
  long long n;
  cin >> n;
  long long a = 1e9, b = 1e9, c = 1e9, ab = 1e9, ac = 1e9, bc = 1e9, ans = 1e9;
  while (n--) {
    long long x;
    cin >> x;
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    long long i = 0;
    for (i = 0; i < s.size(); i++) s[i] += ('a' - 'A');
    if (s == "abc")
      ans = min(ans, x);
    else if (s == "a")
      ans = min({ans, x + bc, x + b + c}), a = min(a, x);
    else if (s == "b")
      ans = min({ans, x + ac, x + a + c}), b = min(b, x);
    else if (s == "c")
      ans = min({ans, x + ab, x + a + b}), c = min(c, x);
    else if (s == "ab")
      ans = min(ans, x + c), ab = min(ab, x), a = min(a, x), b = min(b, x);
    else if (s == "bc")
      ans = min(ans, x + a), bc = min(bc, x), b = min(b, x), c = min(c, x);
    else if (s == "ac")
      ans = min(ans, x + b), ac = min(ac, x), c = min(c, x), a = min(a, x);
  }
  if (ans == 1e9)
    cout << -1;
  else
    cout << ans << endl;
}
