N, K = map(int, input().split())
lis = []
for i in range(K):
    L, R = map(int, input().split())
    for j in range(L, R + 1):
        lis.append(j)

print(lis)


dp = [0] * 2 * N
dp[N] = 1
for i in range(1, N):
    for j in lis:
        dp[N + i] += dp[N + i - j]

print(dp[2 * N - 1] % 998244353)
