N, K = map(int, input().split())
mod = 998244353

tiles = []
for i in range(K):
    L, R = map(int, input().split())
    tiles = tiles + list(range(L, R + 1))
tiles = sorted(tiles)

dp = [0] * (N + 1)
dp[1] = 1

for i in range(2, N + 1):
    for tile in tiles:
        if i - tile < 0: break
        dp[i] = (dp[i] + dp[i - tile]) % mod

print(dp[-1])