n,k=map(int,input().split())
l=[]
for _ in range(k):
    a,b=map(int,input().split())
    for i in range(a,b+1):
        l.append(i)
dp=[0]*(n+1)
for i in range(1,n+1):
    if i in l:
        dp[i]+=1
    for j in l:
        if j<=i:
            dp[i]+=dp[i-j]
            dp[i]%=998244353
print(dp[-2])