#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ull = unsigned long long; using ll = long long; using ld = long double; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep2(i, n, m) for (ll i = n; i <= m; ++i) #define rep3(i, n, m) for (ll i = n; i >= m; --i) template using pqg = priority_queue, greater>; template using pq = priority_queue; template inline bool chmax(S &a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(S &a, T b) { if (a > b) { a = b; return true; } return false; } int main() { int n; cin >> n; ll ans = 5e18; while (n--) { string s; cin >> s; char mx = 0; rep(i, s.size()) mx = max(mx, s[i]); ll w = (isalpha(mx) ? mx - 'A' + 11 : mx - '0' + 1); ll weight = 1; reverse(all(s)); ll val = 0; rep(i, s.size()) { ll d; if (isalpha(s[i])) d = s[i] - 'A' + 10; else d = s[i] - '0'; val += weight * d; weight *= w; } chmin(ans, val); } cout << ans << endl; return 0; }