a,b=gets.split.map{|i|'%020d'%i} 20.times.any?{|i|x,y=a[i],b[i] z=x<=>y [x,y].sort==[?4,?7]?R=-z:x!=y ? R=z: p} $><<[0,a,b][R].to_i