N, K = map(int, input().split())
S = []

for i in range(K):
  l, r = map(int, input().split())
  S.extend(list(range(l,r+1,1)))

c = [0]*N
c[N-1] = 1
ans = 0
for i in range(N):
  if c[N-1-i] == 0:
    continue
  for j in range(len(S)):
    if N-1-i-S[j]<0:
      continue
    elif N-1-i-S[j]==0:
      ans += c[N-1-i]
    else:
      c[N-1-i-S[j]]+=c[N-1-i]

print(ans%998244353)