N,K = map(int,input().split())
LR = []
for i in range(K):
  L,R = map(int,input().split())
  LR += list(range(L,R+1))
LR = sorted(LR)
MOD = 998244353
dp = [0]*N
dp[0] = 1
for i in range(1,N):
  for j in LR:
    if i-j<0: continue
    else: dp[i] += dp[i-j]
  dp[i] %= MOD
print(dp[-1])