n,k=[int(i) for i in raw_input().split()]
l=[[int(i) for i in raw_input().split()]for j in range(k)]
dp=[0 for i in range(n+1)]
dp[1]=1
dp1=[0 for i in range(n+1)]
dp1[1]=1
m=998244353
for i in range(2,n+1):
    dp1[i]=dp1[i-1]
    for j in l:
        if(i-j[1]>0):
            dp[i]+=dp1[i-j[0]]-dp1[i-j[1]-1]
        else:
            dp[i]+=dp1[i-j[0]]
    dp1[i]+=dp[i]
    dp1[i]%=m
    dp[i]%=m
print dp[n]%m
