import collections

N, K = map(int, input().split())
L = list()
R = list()
for _ in range(K):
    line = list(map(int, input().split()))
    L.append(line[0])
    R.append(line[1] + 1)

dp = [0] * N
dp[0] = 1
for i in range(1, N):
    for left, right in zip(L, R):
        for d in range(left, right):
            if d > i:
                break
            dp[i] += dp[i - d]
            dp[i] %= 998244353
print(dp[-1])
