n, k = map(int, input().split())
l, r = map(int, input().split())
s = list(range(l, r+1))
for i in range(1, k):
    l, r = map(int, input().split())
    s = s + list(range(l, r+1))
dp = [0] * n
dp[0] = 1
for i in range(1, n):
    for j in s:
        if i >= j:
            dp[i] += dp[i-j]
    dp[i] = dp[i]%998244353
print(dp[-1])