import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Array

main :: IO ()
main = do
  [n,m] <- getl $ wrds toInt
  solve n <$> replicateM m (getl $ wrds toInt) >>= print

solve :: Int -> [[Int]] -> Int
solve n xs = length $ nub $ f $ foldl move [ia] xs
  where
    ia = array (1,n) ((1,(1,0)) : [(i,(0,1)) | i <- [2..n]]) :: Array Int (Int,Int)
    f = map (\a -> fst $ head $ filter (\(i,(b,c)) -> b == 1) (assocs a))

move :: [Array Int (Int,Int)] -> [Int] -> [Array Int (Int,Int)]
move as [i,j] = do
  a <- as
  case (a ! i) of
   (1,0) -> [accum (\(x0,y0) (x1,y1) -> (x0+x1,y0+y1)) a [(i,(-1,0)),(j,(1,0))]]
   (1,n) -> [accum (\(x0,y0) (x1,y1) -> (x0+x1,y0+y1)) a [(i,(-1,0)),(j,(1,0))], accum (\(x0,y0) (x1,y1) -> (x0+x1,y0+y1)) a [(i,(0,-1)),(j,(0,1))]]
   (0,n) -> [accum (\(x0,y0) (x1,y1) -> (x0+x1,y0+y1)) a [(i,(0,-1)),(j,(0,1))]]
   
toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine
