#include #include #include #include #include #include #include #include using namespace std; int N; vector V; map> M; void input(istream& in) { in >> N; V.resize(N); for (int i = 0; i < N; i++) { in >> V[i]; } } struct less_string { bool operator()(const string& a, const string& b) const { return a < b; } }; int64_t resolve() { int base = 0x7F; for (string& s : V) { for (char ch : s) { if (ch > base) { base = ch; } } size_t nz = s.find_first_not_of('0'); M[s.length() - nz].push_back(s.substr(nz)); } base = (base < 'A') ? (base - '0') : (base - 'A' + 10); base++; vector& shortest_strings = M.begin()->second; string& smallest_value = *min_element(shortest_strings.begin(), shortest_strings.end(), less_string()); int64_t value = 0; for (char ch : smallest_value) { value *= base; value += (ch < 'A') ? (ch - '0') : (ch - 'A' + 10); } return value; } int main() { input(cin); cout << resolve() << endl; return 0; }