N, K, *LR = [int(_) for _ in open(0).read().split()]
L = LR[::2]
R = LR[1::2]
mod = 998244353
dp = [0] * 3 * N
dp[1] = 1
for s in range(1, N):
    for l, r in zip(L, R):
        for d in range(l, r + 1):
            dp[s + d] += dp[s]
            dp[s + d] %= mod
print(dp[N])
