import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

const long INF = 1L << 59;

void main() {
    auto N = readln.chomp.to!int;
    auto dp = new long[](1 << 3);
    fill(dp, INF);
    dp[0] = 0;

    foreach (_; 0..N) {
        auto s = readln.split;
        auto c = s[0].to!long;
        auto S = s[1];
        int mask = 0;
        if (S.canFind('A')) mask |= 1;
        if (S.canFind('B')) mask |= (1 << 1);
        if (S.canFind('C')) mask |= (1 << 2);
        foreach (nmask; 0..8) {
            dp[mask | nmask] = min(dp[mask | nmask], dp[nmask] + c);
        }
    }

    writeln( dp[7] == INF ? -1 : dp[7] );
}
