N, K = map(int, input().split())
mod = 998244353
dp = [0] * N
dp[0] = 1

lr = []
for _ in range(K):
    l, r = map(int, input().split())
    for x in range(l, r+1):
        lr.append(x)
lr.sort()
for i in range(N-1):
    for x in lr:
        if x + i < N:
           dp[x+i] += dp[i]
           dp[x+i] %= mod
        else:
            break
print(dp[N-1])