from bisect import bisect_left as bl
mod=998244353

N,K=map(int,input().split())
LR=[list(map(int,input().split())) for _ in range(K)]
LR.sort()
num=[]
for l in LR:
    for i in range(l[0],l[1]+1):
        num.append(i)


dp=[0 for _ in range(N)]
dp[0]=1

for i in range(N):
    f=bl(num,N-i)
    for n in num[:f+1]:
        if i+n<N:
            dp[i+n]+=dp[i]
            dp[i+n]%mod
#print(dp)
print(dp[-1]%mod)