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: MOD = 998244353
  class SegmentTree:
      def __init__(self, a):
          self.padding = 0
          self.n = len(a)
          self.N = 2 ** (self.n-1).bit_length()
          self.seg_data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-self.n)
          for i in range(2*self.N-2, 0, -2):
              self.seg_data[(i-1)//2] = self.seg_data[i] + self.seg_data[i-1]
      
      def __len__(self):
          return self.n
      
      def update(self, i, x):
          idx = self.N - 1 + i
          self.seg_data[idx] += x
          self.seg_data[idx] %= MOD
          while idx:
              idx = (idx-1) // 2
              self.seg_data[idx] = (self.seg_data[2*idx+1] + self.seg_data[2*idx+2]) % MOD
      
      def query(self, i, j):
          # [i, j)
          if i == j:
              return self.seg_data[self.N - 1 + i] % MOD
          else:
              idx1 = self.N - 1 + i
              idx2 = self.N - 2 + j # 閉区間にする
              result = self.padding
              while idx1 < idx2 + 1:
                  if idx1&1 == 0: # idx1が偶数
                      result = (result + self.seg_data[idx1]) % MOD
                  if idx2&1 == 1: # idx2が奇数
                      result = (result + self.seg_data[idx2]) % MOD
                      idx2 -= 1
                  idx1 //= 2
                  idx2 = (idx2 - 1)//2
              return result
  
  
  N, K = map(int, input().split())
  LR = [tuple(map(int, input().split())) for i in range(K)]
  a = [0] * (N+1)
  a[1] = 1
  dp = SegmentTree(a)
  for i in range(2, N+1):
      for l, r in LR:
          ll = max(0, i - l)
          rr = max(0, i - r)
          dp.update(i, dp.query(rr, ll+1))
  
  print(dp.query(N, N+1))
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."}]