import java.util.*; import java.io.*; import java.math.*; public class No164 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String[] v = new String[n]; for(int i = 0; i < n; i++) { v[i] = sc.next(); } char[] s = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; long ans = Long.MAX_VALUE; for(int i = 0; i < n; i++) { int t = 0; for(int j = 0; j < v[i].length(); j++) { for(int k = 0; k < s.length; k++) { if(v[i].charAt(j) == s[k]) { t = Math.max(t, k); break; } } } ans = Math.min(ans, Long.parseLong(v[i], t+1)); } System.out.println(ans); } }