N,K=map(int,input().split())
MOD=998244353
S=[]
for _ in range(K):
    L,R=map(int,input().split())
    S.append((L,R))
dp=[0]*(N+1)
dp[1]=1
for i in range(2,N+1):
    for j in range(K):
        L,R=S[j][0],S[j][1]
        if L>=i:
            continue
        l=max(0,i-R)
        r=min(i-1,i-L)
        dp[i]+=sum(dp[l:r+1])
        dp[i]%=MOD
print(dp[N]%MOD)