import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long min = Long.MAX_VALUE; for (int i = 0; i < n; i++) { char[] arr = sc.next().toCharArray(); int max = 0; for (char c : arr) { max = Math.max(max, charToInt(c)); } max++; long value = 0; for (char c : arr) { value *= max; value += charToInt(c); } min = Math.min(min, value); } System.out.println(min); } static int charToInt(char c) { if (c <= '9') { return c - '0'; } else { return c - 'A' + 10; } } }