n, m = gets.strip.split(' ').map(&:to_i) #p n, m @matrix = [] (1..n).each do |i| @matrix[i] = [] end m.times do s, e = gets.strip.split(' ').map(&:to_i) @matrix[s] << e @matrix[e] << s end #p @matrix s = 1 path = [s] def dfs(v, path) return if path.length > 5 @matrix[v].each do |next_v| if next_v == 1 && path.length == 5 puts "YES" exit end if @matrix[v].include?(next_v) && !path.include?(next_v) dfs(next_v, path << next_v) end end end dfs(s, path) puts "NO"