MOD = 998244353
N,K = map(int,input().split())
lr = []
for i in range(K):
    lr.append(list(map(int,input().split())))
dp = [0] * (10**6)
dp[0] = 1
dpcum = [0] * (10**6)
dpcum[0] = 1
for i in range(1,N+1):
    for j in range(K):
        dp[i] += dpcum[max(-1,i-lr[j][0])] - dpcum[max(-1,i-lr[j][1]-1)]
        dp[i] %= MOD
    dpcum[i] = (dpcum[i-1] + dp[i]) % MOD
#print(dp)
print(dp[N-1])