a,b=gets.split.map{|i|('%020d'%i).chars} r=z=a<=>b a.zip(b).any?{|c|c.sort*''=='47'?r=-z:z!=0?r=z:p};p ([0,a,b][r]*'').to_i