using System.Collections.Generic; using System.Linq; using System.Numerics; using System; public class Hello { public static void Main() { var z = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var d = new Dictionary(); for (int i = 0; i < 36; i++) d[z[i]] = i; var ans = new List(); var n = int.Parse(Console.ReadLine().Trim()); for (int i = 0; i < n; i++) { var s = Console.ReadLine().Trim(); var a = getN(d, s); var a2 = getV(d, s, a); ans.Add(a2); } Console.WriteLine(ans.Min()); } public static int getN (Dictionary d, string s) { var ans = 0; for (int i = 0; i < s.Length; i++) ans = Math.Max(ans, d[s[i]]); return ans + 1; } public static BigInteger getV (Dictionary d , string s , int n) { var sL = s.Length; BigInteger ans = 0; for (int i = 0; i < sL; i++) ans += (BigInteger)Math.Pow(n, sL - 1 - i) * d[s[i]]; return ans; } }