n = int(input()) ans = 10 ** 50 for _ in range(n): v = input() lst = [] for num in v: if num in "0123456789": lst.append(int(num)) else: lst.append(ord(num) - 55) p = max(max(lst) + 1, 2) total = 0 for i in range(len(lst)): total += (p ** i) * lst[-1 - i] ans = min(ans, total) print(ans)