output_description: Print the number of ways for Tak to go from Cell 1 to Cell N, modulo
  998244353.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
      L_1 R_1
      L_2 R_2
      :
      L_K R_K
attempt: import sys
  
  readline = sys.stdin.readline
  
  import sys
  
  readline = sys.stdin.readline
  
  MOD = 998244353
  
  
  def frac(limit):
      frac = [1] * limit
      for i in range(2, limit):
          frac[i] = i * frac[i - 1] % MOD
      fraci = [None] * limit
      fraci[-1] = pow(frac[-1], MOD - 2, MOD)
      for i in range(-2, -limit - 1, -1):
          fraci[i] = fraci[i + 1] * (limit + i + 1) % MOD
      return frac, fraci
  
  
  frac, fraci = frac(1341398)
  pr = 3
  LS = 20
  
  
  class NTT:
      def __init__(self):
          self.N0 = 1 << LS
          omega = pow(pr, (MOD - 1) // self.N0, MOD)
          omegainv = pow(omega, MOD - 2, MOD)
          self.w = [0] * (self.N0 // 2)
          self.winv = [0] * (self.N0 // 2)
          self.w[0] = 1
          self.winv[0] = 1
          for i in range(1, self.N0 // 2):
              self.w[i] = (self.w[i - 1] * omega) % MOD
              self.winv[i] = (self.winv[i - 1] * omegainv) % MOD
          used = set()
          for i in range(self.N0 // 2):
              if i in used:
                  continue
              j = 0
              for k in range(LS - 1):
                  j |= (i >> k & 1) << (LS - 2 - k)
              used.add(j)
              self.w[i], self.w[j] = self.w[j], self.w[i]
              self.winv[i], self.winv[j] = self.winv[j], self.winv[i]
  
      def _fft(self, A):
          M = len(A)
          bn = 1
          hbs = M >> 1
          while hbs:
              for j in range(hbs):
                  A[j], A[j + hbs] = A[j] + A[j + hbs], A[j] - A[j + hbs]
                  if A[j] > MOD:
                      A[j] -= MOD
                  if A[j + hbs] < 0:
                      A[j + hbs] += MOD
              for bi in range(1, bn):
                  wi = self.w[bi]
                  for j in range(bi * hbs * 2, bi * hbs * 2 + hbs):
                      A[j], A[j + hbs] = (A[j] + wi * A[j + hbs]) % MOD, (
                          A[j] - wi * A[j + hbs]
                      ) % MOD
              bn <<= 1
              hbs >>= 1
  
      def _ifft(self, A):
          M = len(A)
          bn = M >> 1
          hbs = 1
          while bn:
              for j in range(hbs):
                  A[j], A[j + hbs] = A[j] + A[j + hbs], A[j] - A[j + hbs]
                  if A[j] > MOD:
                      A[j] -= MOD
                  if A[j + hbs] < 0:
                      A[j + hbs] += MOD
              for bi in range(1, bn):
                  winvi = self.winv[bi]
                  for j in range(bi * hbs * 2, bi * hbs * 2 + hbs):
                      A[j], A[j + hbs] = (A[j] + A[j + hbs]) % MOD, winvi * (
                          A[j] - A[j + hbs]
                      ) % MOD
              bn >>= 1
              hbs <<= 1
  
      def convolve(self, A, B):
          LA = len(A)
          LB = len(B)
          LC = LA + LB - 1
          M = 1 << (LC - 1).bit_length()
          A += [0] * (M - LA)
          B += [0] * (M - LB)
          self._fft(A)
          self._fft(B)
          C = [0] * M
          for i in range(M):
              C[i] = A[i] * B[i] % MOD
          self._ifft(C)
          minv = pow(M, MOD - 2, MOD)
          for i in range(LC):
              C[i] = C[i] * minv % MOD
          return C[:LC]
  
          return C
  
      def inverse(self, A):
          LA = len(A)
          dep = (LA - 1).bit_length()
          M = 1 << dep
          A += [0] * (M - LA)
  
          g = [pow(A[0], MOD - 2, MOD)]
          for n in range(dep):
              dl = 1 << (n + 1)
              f = A[:dl]
              fg = self.convolve(f, g[:])[:dl]
              fgg = self.convolve(fg, g[:])[:dl]
              ng = [None] * dl
              for i in range(dl // 2):
                  ng[i] = (2 * g[i] - fgg[i]) % MOD
              for i in range(dl // 2, dl):
                  ng[i] = MOD - fgg[i]
              g = ng[:]
          return g[:LA]
  
      def integral(self, A):
          A = [1] + [A[i] * fraci[i + 2] % MOD for i in range(len(A))]
  
  
  N, K = map(int, readline().split())
  
  A = [0] * (N + 2)
  for _ in range(K):
      l, r = map(int, readline().split())
      A[l] += 1
      A[r + 1] -= 1
  
  for i in range(1, N + 1):
      A[i] += A[i - 1]
  A = A[:-1]
  A[0] -= 1
  A = [-a % MOD for a in A]
  
  NN = NTT()
  print(NN.inverse(A[:])[N - 1] % MOD)
  
problem_description: Statement
  
  There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to
  right.
  
  Tak lives in these cells and is currently on Cell 1. He is trying to reach
  Cell N by using the procedure described below.
  
  You are given an integer K that is less than or equal to 10, and K non-
  intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the
  union of these K segments. Here, the segment [l, r] denotes the set consisting
  of all integers i that satisfy l \leq i \leq r.
  
    * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells.
  
  To help Tak, find the number of ways to go to Cell N, modulo 998244353.
samples: [{"input": "5 2\n    1 1\n    3 4", "output": "4\n    \n\nThe set S is the union of the segment [1, 1] and the segment [3, 4], therefore\nS = \\\\{ 1, 3, 4 \\\\} holds.\n\nThere are 4 possible ways to get to Cell 5:\n\n  * 1 \\to 2 \\to 3 \\to 4 \\to 5,\n  * 1 \\to 2 \\to 5,\n  * 1 \\to 4 \\to 5 and\n  * 1 \\to 5.\n\n* * *"}, {"input": "5 2\n    3 3\n    5 5", "output": "0\n    \n\nBecause S = \\\\{ 3, 5 \\\\} holds, you cannot reach to Cell 5. Print 0.\n\n* * *"}, {"input": "5 1\n    1 2", "output": "5\n    \n\n* * *"}, {"input": "60 3\n    5 8\n    1 3\n    10 15", "output": "221823067\n    \n\nNote that you have to print the answer modulo 998244353."}]