import numpy as np
N,K = map(int,input().split())
LR = []
for _ in range(K):
  L,R = map(int,input().split())
  LR += list(range(L,R+1))
LR = np.array(LR)
MOD = 998244353
dp = np.zeros(N,"i8")
dp[0] = 1
for i in range(N):
  lr = (i+LR)
  lr = lr[lr<N]
  dp[lr] = (dp[lr]+dp[i])%MOD
print(dp[-1])