import java.io.*; import java.nio.*; import java.nio.file.*; import java.util.*; import java.util.concurrent.*; import java.math.*; import java.util.stream.*; public class Main { public static void main(String... args) throws Throwable { Scanner in = new Scanner(System.in); ArrayList list = new ArrayList<>(); int cnt = in.nextInt(); for (int i = 0; i < cnt; i++) { String str = in.next(); list.add(Long.parseLong(str, str.codePoints().map(c -> (int)'A' <= c ? (10 + (c - (int)'A') + 1) : (c - (int)'0' + 1)).max().getAsInt())); } System.out.println(Collections.min(list)); } }