N,K=map(int,input().split())
T=[0]*(N+1)
p=998244353
for i in range(K):
  a,b=map(int,input().split())
  for j in range(a,b+1):
    T[j]+=1

dp=[0]*N
dp[0]=1
for i in range(1,N):
  dp[i]=sum([x for j,x in enumerate(dp) if i>=j and T[i-j]==1])%p
print(dp[-1]%p)