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

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

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

for i in range(1,N):
  for j in S:
    if i >= j:
      DP[i] += DP[i-j]
      
print(DP[-1]%998244353)