n = gets.to_i a = [] for i in 1..n a.push(gets.to_s) end t = 0 dic = {} for s in "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars dic[s] = t t += 1 end ar = [] for i in 0..n-1 ar.push(a[i].to_i(dic[a[i].chars.max]+1)) end puts ar.min