import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long min = Long.MAX_VALUE; int[] shinsu = new int[91]; for (int i = 0; i < shinsu.length; i++) { if (i <= 57) { shinsu[i] = i - 47; } else { shinsu[i] = i - 54; } } for (int n = 0; n < N; n++) { int max = 0; char[] input = sc.next().toCharArray(); /* * char の 0~9はintの48~57 A~Zは65~90 */ for (int i = 0; i < input.length; i++) { max = Math.max(max, (int) input[i]); } int shinho = shinsu[max]; long ans = 0; long now = 1; for (int i = 0; i < input.length; i++) { char c = input[input.length - 1 - i]; int conv = convert(c); ans += conv * now; now *= shinho; } min = Math.min(min, ans); } System.out.println(min); } static int convert(char c) { int n = (int) c; if (n <= 57) { n -= 48; } else { n -= 55; } return n; } }