N,K=map(int,input().split())
lr= [map(int, input().split()) for _ in range(K)]
l,r= [list(i) for i in zip(*lr)]

mod=998244353

dp=[0]*N
dp[0]=1
dpsum=[0]*(N+1)
dpsum[0]=1
for i in range(1,N):
    for j in range(K):
        li=i-r[j]
        ri=i-l[j]
        if ri<0:
            continue
        li=max(li,0)
        if li-1<0:
            dpsum[li-1]=0
        dp[i]+=dpsum[ri]-dpsum[li-1]
    dpsum[i]=(dpsum[i-1]+dp[i])


print(dp[N-1]%mod)