import Control.Monad (replicateM) f777 :: Int -> Int -> Int -> [Integer] -> Bool f777 left right n xs | left == n = False | s == 777 = True | isIncR = f777 left (right + 1) n xs | otherwise = f777 (left + 1) right n xs where s = sum $ take (right - left) $ drop left xs isIncR = left == right || (right /= n && s + xs !! right <= 777) solve :: Int -> [Integer] -> [[Integer]] -> String solve n a as | f777 0 1 n a = "YES" | as == [] = "NO" | otherwise = solve n (zipWith (+) a (head as)) (tail as) main = do [n, m] <- map read . words <$> getLine :: IO [Int] as <- map (map read . words) <$> replicateM m getLine :: IO [[Integer]] putStrLn $ solve n (head as) (tail as)