#include <bits/stdc++.h>
using namespace std;
vector<int> adj;
int vst[1000001];
int main() {
  int arr[7] = {}, n;
  for (long long i = 0; i < 7; i++) {
    arr[i] = 1000000007;
  }
  cin >> n;
  for (long long i = 0; i < n; i++) {
    int a;
    string s;
    cin >> a >> s;
    int l = s.size();
    if (l == 1) {
      if (arr[s[0] - 'A'] > a) {
        arr[s[0] - 'A'] = a;
      }
    } else if (l == 2) {
      if (s == "AB" || s == "BA") {
        if (arr[3] > a) {
          arr[3] = a;
        }
      } else if (s == "BC" || s == "CB") {
        if (arr[4] > a) {
          arr[4] = a;
        }
      } else {
        if (arr[5] > a) {
          arr[5] = a;
        }
      }
    } else {
      if (arr[6] > a) {
        arr[6] = a;
      }
    }
  }
  int sum = 1000000007;
  if (arr[0] != 1000000007 && arr[1] != 1000000007 && arr[2] != 1000000007) {
    if ((arr[0] + arr[1] + arr[2]) < sum) {
      sum = (arr[0] + arr[1] + arr[2]);
    }
  }
  if (arr[0] != 1000000007 && arr[4] != 1000000007) {
    if ((arr[0] + arr[4]) < sum) {
      sum = (arr[0] + arr[4]);
    }
  }
  if (arr[1] != 1000000007 && arr[5] != 1000000007) {
    if ((arr[1] + arr[5]) < sum) {
      sum = (arr[1] + arr[5]);
    }
  }
  if (arr[2] != 1000000007 && arr[3] != 1000000007) {
    if ((arr[2] + arr[3]) < sum) {
      sum = (arr[2] + arr[3]);
    }
  }
  if (arr[3] != 1000000007 && arr[4] != 1000000007) {
    if ((arr[3] + arr[4]) < sum) {
      sum = (arr[3] + arr[4]);
    }
  }
  if (arr[4] != 1000000007 && arr[5] != 1000000007) {
    if ((arr[4] + arr[5]) < sum) {
      sum = (arr[4] + arr[5]);
    }
  }
  if (arr[3] != 1000000007 && arr[5] != 1000000007) {
    if ((arr[3] + arr[5]) < sum) {
      sum = (arr[3] + arr[5]);
    }
  }
  if (arr[6] != 1000000007) {
    if ((arr[6]) < sum) {
      sum = arr[6];
    }
  }
  if (sum == 1000000007)
    cout << -1;
  else
    cout << sum;
}
