N,K = map(int,input().split())
LR = []
mod = 998244353
for i in range(K):
    L,R = map(int,input().split())
    LR.append((L,R))
dp = [0]*(3*N)
for L,R in LR:
    dp[L] += 1
    dp[L] %= mod
    dp[R+1] -= 1
    dp[R+1] %= mod
for i in range(1,N-1):
    for L,R in LR:
        dp[i+L] += dp[i]
        dp[i+L] %= mod
        dp[i+R+1] -= dp[i]
        dp[i+R+1] %= mod
    dp[i+1] += dp[i]
    dp[i+1] %= mod
print(dp[N-1])