def code(c): if (c.isdigit()): return ord(c) - ord('0') else: return ord(c) - ord('A') + 10 def main(): n = int(input()) ans = 10**50 for _ in range(n): s = input() b = max([code(c) for c in s]) + 1 x = 0 for c in s: x = x * b + code(c) ans = min(ans, x) print(ans) if __name__ == "__main__": main()