def g;gets.split.map(&:to_i)end n,m=g l=Hash.new{[]} m.times{ *a,c=g l[c]+=[a] } now=*1..n g.each{|c|now=l[c].flat_map{|a|a.select{|i|now.index(*(a-[i]))}}} puts now.size,now*" "