n = int(raw_input()) ll = [list(raw_input()) for _ in range(n)] mn = 36**13 for l in ll: m = [] for c in l: if c >= 'A': m.append(ord(c)-ord('A')+10) else: m.append(ord(c)-ord('0')) base = max(m)+1 m.reverse() s = 0 mul = 1 for i in m: s += i*mul mul *= base mn = min(mn,s) print mn