MOD = 998244353
N, K = map(int, input().split())
S = set()

for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        S.add(j)

S = sorted(list(S))
dp = [0] * (N + 1)
flag = [0] * (N + 1)
dp[1] = 1

for i in range(2, N + 1):
    temp = dp[i]
    for step in S:
        if step > i:
            break
        temp += dp[i - step]
        temp %= MOD
    dp[i] = temp
    
print(dp[N])
