N,K = map(int, input().split())
mod = 998244353

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

step = [0 for _ in range(N)]
step[0] = 1
step[1] = -1
answer = 0

for i in range(N):
  answer = (answer+step[i])%mod
  for L,R in LR:
    if i+L < N:
      step[i+L] += answer
    if i+R+1 < N:
      step[i+R+1] -= answer

print((answer)%mod)