#include <bits/stdc++.h>
using namespace std;
map<string, long long> mp;
string S[1006];
long long cost[1006];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int N, i, j, k;
  cin >> N;
  mp["A"] = 1e9;
  mp["B"] = 1e9;
  mp["C"] = 1e9;
  mp["AB"] = 1e9;
  mp["AC"] = 1e9;
  mp["BC"] = 1e9;
  mp["ABC"] = 1e9;
  for (i = 1; i <= N; i++) {
    cin >> cost[i] >> S[i];
    sort(S[i].begin(), S[i].end());
    mp[S[i]] = min(mp[S[i]], cost[i]);
  }
  mp["AB"] = min(mp["AB"], mp["A"] + mp["B"]);
  mp["AC"] = min(mp["AC"], mp["A"] + mp["C"]);
  mp["BC"] = min(mp["BC"], mp["B"] + mp["C"]);
  mp["ABC"] = min(mp["ABC"], mp["AB"] + mp["C"]);
  mp["ABC"] = min(mp["ABC"], mp["A"] + mp["BC"]);
  mp["ABC"] = min(mp["ABC"], mp["AC"] + mp["B"]);
  mp["ABC"] = min(mp["ABC"], mp["AB"] + mp["BC"]);
  mp["ABC"] = min(mp["ABC"], mp["AC"] + mp["BC"]);
  mp["ABC"] = min(mp["ABC"], mp["AB"] + mp["AC"]);
  mp["ABC"] = min(mp["ABC"], mp["A"] + mp["B"] + mp["C"]);
  if (mp["ABC"] >= (long long)1e9)
    printf("-1\n");
  else
    printf("%d\n", mp["ABC"]);
  return 0;
}
