n, k = list(map(int, input().split()))
s = [0] * k
for i in range(k):
    lr = list(map(int, input().split()))
    s[i] = lr

mod = 998244353
i = 1
dp = [0] * (n+1)
dp[i] = 1
for i in range(n+1):
    for lr in s:
        for d in range(lr[0], lr[1]+1):
            if i+d <= n:
                dp[i+d] += dp[i] % mod

print(dp[n] % mod)
