#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(), (a).end() int main() { cin.tie(nullptr); int N; cin >> N; vector res(N, 0); rep(num, 0, N) { string V; cin >> V; int siz = V.size(); reverse(all(V)); vector d(siz); rep(i, 0, siz) { if (V[i] - 'A' >= 0) d[i] = V[i] - 'A' + 10; else d[i] = V[i] - '0'; } ll base = -1; rep(i, 0, siz) base = max(base, d[i]); base += 1; ll t = 1; rep(i, 0, siz) { res[num] += t * d[i]; t *= base; } } sort(all(res)); cout << res[0] << '\n'; }