mod=998244353
N,K=[int(r) for r in input().split()]
T=[]
for i in range(K):
  a,b=[int(r) for r in input().split()]
  for j in range(a,b+1):
    T.append(j)
S=set(T)

dp=[0]*(N+1)
dp[1]=1

for i in range(1,N+1):
  for s in S:
    if i-s > 0:
      dp[i]+=dp[i-s]%mod


print(dp[N]%mod)

