import sys
input = sys.stdin.readline

N,K=map(int,input().split())
K=[tuple(map(int,input().split())) for i in range(K)]
mod=998244353

DP=[0]*(4*10**5+100)
DP[1]=1
DP[2]=-1

for i in range(1,N+1):
    DP[i]+=DP[i-1]
    DP[i]%=mod
    
    for l,r in K:
        DP[i+l]+=DP[i]
        DP[i+l]%=mod
        DP[i+r+1]-=DP[i]
        DP[i+r+1]%=mod
        

    #print(DP[:10])

print(DP[N])
    
