N = input() smallest = 10**20 for loop in xrange(N): S = raw_input() base = 36 while True: try: int(S, base) base -= 1 except: break base += 1 smallest = min(smallest, int(S, base)) print smallest