class Yukicoder LIST = [*('0'..'9')] + [*('A'..'Z')] def initialize n = gets.chomp.to_i min_value = Float::INFINITY n.times do str = gets.chomp e = str.chars.map{|ch| LIST.index(ch)}.max min_value = [min_value, encode(str, e+1)].min end puts min_value end def encode(str, e) str.to_i(e) end end Yukicoder.new