// 想定解: やるだけ #include using namespace std; typedef long long ll; template void rc(_T v,_T mn,_T mx){if(v='0'&&c<='9'?c-'0':c>='A'&&c<='Z'?c-'A'+10:c>='a'&&c<='z'?c-'a'+10:throw);} ll solve(const string &s){ vector v; int b = 0; for(auto c : s){ int n = c2n(c); v.push_back(n); b = max(b,n+1); } ll res = 0; for(auto n : v) res = (res * b + n); return res; } int main(){ int N; cin >> N; rc(N, 1, 1000); ll minv = LLONG_MAX; REP(i,N){ string s; cin >> s; rc(int(s.size()), 1, 12); minv = min(minv, solve(s)); } cout << minv << endl; string s; if(cin >> s) throw; }