N, M = gets.split.map(&:to_i) E = Hash.new { |h, k| h[k] = [] } M.times do a, b = gets.split.map(&:to_i) E[a] << b E[b] << a end def is_connected_graph? queue = [] queue << E.first.first visited = Array.new(N + 1, false) cnt = 0 until queue.empty? v = queue.shift next if visited[v] visited[v] = true cnt += 1 E[v].each do |u| queue << u end end cnt == E.size end def f E.all? { |u, list| list.size.even? } end def g odd_cnt = 0 even_cnt = 0 E.each do |u, list| if list.size.even? even_cnt += 1 else odd_cnt += 1 end end odd_cnt == 2 end if is_connected_graph? && (f || g) puts 'YES' else puts 'NO' end