N,K=map(int,input().split())
seg=[]
for _ in range(K):
    L,R=map(int,input().split())
    for i in range(L,R+1):
        seg.append(i)

num=len(seg)
ans=[1]
for i in range(1,N):
    val=0
    for k in range(num):
        ad=i-seg[k]
        if ad>=0:
            val+=ans[ad]
    ans.append(val)
print(ans[N-1]%998244353)