import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  let
    modulus = 998244353 :: Int
    modAdd :: Int -> Int -> Int
    modAdd x y = (x + y) `mod` modulus
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  lrs <- map (fmap succ . unsafeListToPair . map unsafeTextToInt . T.words) . T.lines <$> T.getContents :: IO [(Int, Int)]
  let
    (ls, rs) = unzip lrs :: ([Int], [Int])
    dp = VU.constructN n rec :: VU.Vector Int
      where
        rec :: VU.Vector Int -> Int
        rec v | l == 0    = 1
              | l == 1    = ((foldl modAdd 0 . map (v VU.!) . filter (0 <=). map (l -) $ ls) - (foldl modAdd 0 . map (v VU.!) . filter (0 <=) . map (l -) $ rs)) `mod` modulus
              | otherwise = (VU.last v + (foldl modAdd 0 . map (v VU.!) . filter (0 <=). map (l -) $ ls) - (foldl modAdd 0 . map (v VU.!) . filter (0 <=) . map (l -) $ rs)) `mod` modulus
          where
            l = VU.length v :: Int
  print . VU.last $ dp

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair = (,) <$> head <*> head . tail
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}
