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