n,k = map(int, input().split())
lr=[list(map(int,input().split())) for i in range(k)]
mod=998244353

imos=[0]*(n+10)
imos[0]=1

now=0
for i in range(n):
    now+=imos[i]
    for j in range(k):
        l,r=lr[j]
        if i+l>n:
            continue
        imos[i+l]+=now
        imos[i+l]%=mod
        if i+r>n:
            continue
        imos[i+r+1]-=now
        imos[i+r+1]%=mod

print(imos[n-1]%mod)