N,K=map(int,input().split())
I=[0]*K
for m in range(K):
    l,r=map(int,input().split())
    I[m]=(l,r)

Mod=998244353

DP=[0]*(N+1)
DP[1]=1

for x in range(2,N+1):
    DP[x]=DP[x-1]
    for (l,r) in I:
        a=max(0,x-r-1)
        b=max(0,x-l)
        DP[x]+=DP[b]-DP[a]
        DP[x]%=Mod
print((DP[N]-DP[N-1])%Mod)