#include using namespace std; using ll = long long; using ul = unsigned long; using ull = unsigned long long; template inline bool chmin(T& a, T b) { if (a > b) a = b; return a > b; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; ll res{ (ll)1e20 }; for (int i = 0; i < n; ++i) { string s; cin >> s; string sw(s); sort(sw.rbegin(), sw.rend()); char m = sw[0]; char r = (m <= '9' ? '0' : 'A' - 10); int mm = m - r + 1; ll x = 1, sum{ 0 }; for (int d = (int)s.size() - 1; d >= 0; --d) { if (s[d] <= '9') sum += (s[d] - '0') * x; else sum += (s[d] - 'A' + 10) * x; x *= mm; } chmin(res, sum); } cout << res << "\n"; return 0; }