N, K = map(int, input().split())
L = [0] * K
R = [0] * K
S = set()
for k in range(K):
    L[k],R[k] = map(int,input().split())
for k in range(K):
    for n in range(L[k], R[k] + 1):
        S.add(n)
dp = [0] * (N+1)
dp[1] = 1
S = sorted(S)
for i in range(1,N+1):
    for s in S:    
        if i-s <= 0:
            break
        dp[i] += dp[i-s]
        if dp[i] >= 498244353:
            dp[i] -= 998244353
while dp[N] >= 998244353:
    dp[N] -= 998244353
while dp[N] < 0:
    dp[N] += 998244353    
print(dp[N])