#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; char getBiggestChar(string &s) { char ret = s[0]; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < s.size(); j++) { if (s[j] > ret) { ret = s[j]; } } } return ret; } bool isNumber(char c) { return c <= '9'; } int toNumber(char c) { int ret = (int)c; if (isNumber(c)) { ret -= '0'; } else { ret -= 'A' - 10; } return ret; } int toBase(char c) { return toNumber(c) + 1; } long long encode(string s, int b) { long long ret = 0; long long mul = 1; for (int i = 0; i < s.size(); i++) { int num = toNumber(s[s.size() - 1 - i]); ret += num * mul; mul *= b; } return ret; } int main(void) { std::ios::sync_with_stdio(false); std::cin.tie(0); int N; cin >> N; vector V; for (int i = 0; i < N; i++) { string s; cin >> s; V.push_back(s); } long long min = -1; for (int i = 0; i < V.size(); i++) { int base = toBase(getBiggestChar(V[i])); long long encoded = encode(V[i], base); if ((encoded < min) || (min == -1)) { min = encoded; } } cout << min << endl; }