N,K=map(int,input().split())
S=set()
for _ in range(K):
    l,r=map(int,input().split())
    S = S | set(list(range(l,r+1)))
    
dp=[0]*(N+1)
dp[1]=1

for n in range(2,N+1):
    for i in range(1,n):
        if i in S:
            dp[n]=(dp[n]+dp[n-i])%998244353

print(dp[-1])