a,b=gets.split.map{|i|('%020d'%i).chars} 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