N,K = map(int,input().split())
S = []
for _ in range(K):
    l,r = map(int,input().split())
    S+=[i for i in range(l,r+1)]
S.sort()

dp=[0]*(N+1)
dp[1]=1
 
for i in range(2,N+1):
    for j in S:
        if i<j:
            break
        else:
            dp[i]+=dp[i-j]
            dp[i]%998244353

#print(S)
#print(dp)
print(dp[-1]%998244353)