# coding: utf-8 #yuki_164 import sys def base_convert(nl, ibase, obase): o = [] while any(nl): c = 0 for i in xrange(len(nl)): c = c * ibase + nl[i] nl[i],c = divmod(c,obase) o.append(c) o.reverse() return o def radix(lst): rdx=0 for i in xrange(len(lst)): order=ord(lst[i]) if order>=48 and order<=57: tmp=order-47 if tmp>rdx: rdx=tmp elif order>=65 and order<=90: tmp=order-54 if tmp>rdx: rdx=tmp return rdx n=int(raw_input()) res=sys.maxint for i in xrange(n): s=raw_input() ls=map(str,s) ls2=[] for i in xrange(len(ls)): if s[i].isalpha()==False: ls2.append(int(s[i])) elif s[i].isalpha()==True: ls2.append(ord(s[i])-55) rdx=radix(ls) ls3=base_convert(ls2,rdx,10) rest=int("".join(map(str,ls3))) if rest