import java.io.*; import java.util.*; class Main { public static void out (Object o) { System.out.println(o); } public static long getDecimal (String v) { long ret = 0; String s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int max = 0; for (int i = 0; i < v.length(); i++) { max = Math.max(max , (int)v.charAt(i)); } long k = 1 , d = s.indexOf((char)max) + 1; //out(d); for (int i = v.length() - 1; i >= 0; i--) { ret += s.indexOf(v.charAt(i)) * k; k *= d; } return ret; } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); long ans = Long.MAX_VALUE; for (int i = 0; i < n; i++) { String v = br.readLine(); ans = Math.min(ans , getDecimal(v)); } out(ans); } }