A, B = gets.split.map(&:to_i) x, y = ("%011d" % A).each_char.zip(("%011d" % B).each_char).find {|(a, b)| a != b}.map(&:to_i) ans = if (x == 4 and y == 7) or (not (x == 7 and y == 4) and x > y) A else B end puts ans