n, m = gets.chomp.split.map(&:to_i) #p m #p n trains = Array.new(m).map{Array.new(n,0)} #p trains (0..m-1).each do |i| tmp = gets.chomp.split.map(&:to_i) (0..n-1).each do |j| trains[i][j] = tmp[j] end end # p trains # p trains[0][1] (0..m-1).each do |i| (0..n-2).each do |j| trains[i][j+1] += trains[i][j] end end # p trains (0..m-2).each do |i| (0..n-1).each do |j| trains[i+1][j] += trains[i][j] end end # p trains (0..m-1).each do |i| if (trains[i][0] == 777 || trains[i][n-1] == 777) puts "YES" exit end (1..n-1).each do |j| (0..n-2).each do |k| if trains[i][j] - trains[i][k] == 777 puts "YES" exit end end end end puts 'NO'