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