import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from functools import reduce N = int(readline()) nums = [] for S in readlines(): S = [x - ord('0') if 0 <= x-ord('0') < 10 else x - ord('A') + 10 for x in S.rstrip()] D = max(S) + 1 x = reduce(lambda x,y: D*x + y, S) nums.append(x) answer = min(nums) print(answer)