#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; char getBiggestChar(vector &V) { char ret = V[0][0]; for (int i = 0; i < V.size(); i++) { string s = V[i]; for (int j = 0; j < s.size(); j++) { if (s[j] > ret) { ret = s[j]; } } } return ret; } bool isNumber(char c) { return c <= 57; } int toNumber(char c) { int ret = (int)c; if (isNumber(c)) { ret -= 48; } else { ret -= 55; } return ret; } int toBase(char c) { return toNumber(c) + 1; } int getMinIndex(vector &V) { int mindex = 0; int min = V[0].size(); for (int i = 0; i < V.size(); i++) { string s = V[i]; int j = 0; while (V[i][j] == '0') { j++; } int len = 0; while (j < s.size()) { j++; len++; } if (len < min) { min = len; mindex = i; } else if (len == min) { for (int l = 0; l < s.size(); l++) { if (V[i][l] > V[mindex][l]) { min = len; mindex = i; break; } } } } return mindex; } int encode(string s, int b) { int ret = 0; for (int i = 0; i < s.size(); i++) { int num = toNumber(s[s.size() - 1 - i]); ret += pow(b, i) * num; } 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); } int base = toBase(getBiggestChar(V)); int mindex = getMinIndex(V); cout << encode(V[mindex], base) << endl; }