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

for _ in range(K):
  L, R = map(int, input().split())
  S.extend(range(L,R+1))
  
S.sort()

DP =[0]*N
DP[0] = 1

for i in range(N-1):
  if i + S[0] >= N:
    break
  if DP[i] == 0:
    pass
  else:
    for j in S:
      if i+j<N:
        DP[i+j] += DP[i]
      else:
        break

print(DP[-1]%998244353)