(n,m),*a=$<.map{|e|e.split.map &:to_i} deg=[r=0]*n ma=[-1]*m people=m.times.map{[]} n.times{|i| m.times{|j| if ma[j]