def main():
  N, K = map(int, input().split())
  dis = []
  mod = 998244353
  for _ in range(K):
    L, R = map(int, input().split())
    if L == R:
      dis.extend([L])
    else:
      dis.extend(list(range(L, R+1)))
  
  lst = [0] * (N+1)
  lst[0] = 1
  for i in range(1, N):
    for j in dis:
      lst[i] += lst[i-j]
    if lst[i] >= mod:
      lst[i] = lst[i] % mod
  print(lst[i])
  
main()