N,K = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(K)]
LR = sorted(LR)

MOD = 998244353
dp = [0] * (N+1)
dp[1] = 1
for i in range(1,N):
  dp[i]%=MOD
  for l,r in LR:
    if i+l<=N:
      dp[i+l] += dp[i]
    if i+r+1<=N:
      dp[i+r+1] -= dp[i]
      
  if i!=1:
    dp[i+1] += dp[i]
    

print(dp[-1]%MOD)