def main():
    n,k=map(int, input().split())
    s=[]
    for _ in range(k):
        l,r=map(int,input().split())
        for j in range(l,r+1):
            s.append(j)
    mod=998244353
    dp=[0]*n
    dp[0]=1
    for i in range(1,n):
        for j in s:
            if i-j>=0:
                dp[i]+=dp[i-j]
                dp[i]%=mod
    print(dp[-1])
main()