using System; using System.Collections.Generic; class program { public static void Main() { var N = int.Parse(Console.ReadLine()); var V = new string[N]; for (var i = 0; i < N; i++) { V[i] = Console.ReadLine(); } var minVal = int.MaxValue; var minpos = 0; for (var i = 0; i < N; i++) { var rep = 0.0; for (var j = 0; j < V[i].Length; j++) { var c = (int)V[i][j]; if (c >= 'A') { c -= (int)'A'; c += 10; } else { c -= (int)'0'; } rep += Math.Pow(36, V[i].Length - j - 1) * c; } if (rep < minVal) { minVal = (int)rep; minpos = i; } } var k = (int)'0'; foreach (var c in V[minpos]) { k = k < c ? c : k; } if (k >= 'A') { k -= (int)'A'; k += 10; } else { k -= (int)'0'; } k++; double result = 0; for (var i = 0; i < V[minpos].Length; i++) { var c = (int)V[minpos][i]; if (c >= 'A') { c -= (int)'A'; c += 10; } else { c -= (int)'0'; } result += Math.Pow(k, V[minpos].Length - i - 1) * c; } Console.WriteLine((long)result); } }