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


dp = [0] * 2 * N
dp[N] = 1
for i in range(1, N):
    for ll, rr in lis:
        dp[N + i] += sum(dp[(N + i - rr + 1): (N + i - ll + 1)])
print(dp[2 * N - 1] % 998244353)
