#include using namespace std; #define LOG(...) fprintf(stderr,__VA_ARGS__) //#define LOG(...) #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define REP(i,n) for(int i=0;i<(int)(n);++i) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) typedef long long ll; typedef unsigned long long ull; typedef vector vb; typedef vector vi; typedef vector vll; typedef vector vvb; typedef vector vvi; typedef vector vvll; typedef pair pii; typedef pair pll; inline int c2i(char c) { if (c <= '9') { return c - '0'; } else { return c - 'A' + 10; } } int main() { int n; cin >> n; ll mi = LLONG_MAX; REP(i, n) { string s; cin >> s; set cs; REP(j, s.length()) { cs.insert(s[j]); } int base = c2i(*cs.rbegin()) + 1; ll res = 0; REP(j, s.length()) { res = res*base + c2i(s[j]); } mi = min(mi, res); } cout << mi << endl; }