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++) { min = Math.min(min, getValue(sc.next().toCharArray())); } System.out.print(min); } static long getValue(char[] arr) { char max = '0'; for (char c : arr) { max = (char)Math.max(max, c); } int idxed = 0; if (max >= 'A') { idxed = 10 + max - 'A'; } else { idxed = max - '0'; } idxed++; long value = 0; for (char c : arr) { value *= idxed; if (c >= 'A') { value += 10 + c - 'A'; } else { value += c - '0'; } } return value; } }