#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i,n) for(long (i)=0;(i)<(n);(i)++) #define FOR(i,a,b) for(long (i)=(a);(i)<(b);(i)++) #define RREP(i,a) for(long (i)=(a)-1;(i)>=0;(i)--) #define FORR(i,a,b) for(long (i)=(a)-1;(i)>=(b);(i)--) #define MOD 1000000007 #define PI acos(-1.0) #define DEBUG(C) cout< #define PLL pair #define ALL(a) (a).begin(),(a).end() #define SORT(a) sort((a).begin(),(a).end()) #define RSORT(a) sort((a).begin(),(a).end(),greater()) #define MP(a,b) make_pair(a,b) typedef long long LL; typedef unsigned long long ULL; using namespace std; string s="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int func(char c){ if('0'<=c&&c<='9') return c-'0'; else return c-'A'+10; } int main(void){ int N; cin>>N; vector V(N); map mp; int cnt=1; REP(i,s.size()) mp[s[i]]=cnt++; REP(i,N) cin>>V[i]; ULL umin=ULLONG_MAX; REP(i,N){ char cmax=V[i][0]; FOR(j,1,V[i].size()){ cmax=max(cmax,V[i][j]); } int num=mp[cmax]; ULL buf=func(V[i].back()); int cnt=1; RREP(j,V[i].size()-1){ buf+=pow(num,cnt)*func(V[i][j]); cnt++; } umin=min(umin,buf); } cout<