N = int(input()) ans = 10**20 for i in range(N): V = list(input()) L = [0]*len(V) for j in range(len(L)): if '0' <= V[j] <= '9': L[j]=int(V[j]) else: L[j]=ord(V[j])-65+10 n = max(L)+1 temp = 0 L = L[::-1] for j in range(len(L)): temp+=L[j]*n**j ans = min(temp,ans) print(ans)