#include "bits/stdc++.h" #define REP(i,n,N) for(ll i=(n); i<(N); i++) #define RREP(i,n,N) for(ll i=(N-1); i>=n; i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define ALL(v) (v).begin(),(v).end() #define p(s) cout<<(s)<>N){ string v; ll ans=inf; REP(i,0,N){ cin>>v; ll mx=0; REP(j,0,v.size()){ if(isdigit(v[j])){ mx=max(mx, v[j]-'0'); }else{ mx=max(mx, 10LL + v[j]-'A'); } } mx++; ll tmp=0; REP(j,0,v.size()){ tmp*=mx; if(isdigit(v[j])) tmp+=v[j]-'0'; else tmp+=v[j]-'A'+10; } ans=min(ans,tmp); } p(ans); } return 0; }