line = gets.chomp! abort "line 1 format" unless line=~/^\d+ \d+$/ n,m = line.split.map(&:to_i) abort "n" unless 2 <= n && n <= 10000 abort "m" unless 1 <= m && m <= n m.times{|lno| line = gets.chomp! abort "line #{lno+2} format" unless line=~/^\d+ \d+$/ a,b = line.split.map(&:to_i) abort "a [#{lno+2}]" unless 1 <= a && a <= n abort "b [#{lno+2}]" unless 1 <= b && b <= n abort "a == b [#{lno+2}]" unless a != b } abort "eol" unless !gets puts "format OK"