#include #include #include using namespace std; #define RREP(i,s,e) for (i = e-1; i >= s; i--) #define rrep(i,n) RREP(i,0,n) #define REP(i,s,e) for (i = s; i < e; i++) #define rep(i,n) REP(i,0,n) #define INF 1e8 typedef long long ll; ll power(ll a, int n) { if (a == 0) return 1; else return a * power(a,n-1); } int main() { int i, j, n; ll ans; cin >> n; ans = power(36,12); rep (i,n) { int base, w; ll x, v; string s; cin >> s; w = s.size(); base = 0; for (char c : s) { if (isdigit(c)) base = max(base,c - '0'); else base = max(base,c - 'A' + 10); } base++; v = 0; rep (j,w){ if (isdigit(s[w-j-1])) x = s[w-j-1] - '0'; else x = s[w-j-1] - 'A' + 10; v += power(base,j)*x; } ans = min(ans,v); } cout << ans << endl; return 0; }