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