n, k = list(map(int, input().split()))
move = []
for i in range(k):
    s, t = list(map(int, input().split()))
    m = list(range(s, t + 1))
    move += m

mod = 998244353

dp = [0] * (n)
dp[0] = 1

for i in range(n):
    p = i
    temp = 0
    for m in move:
        if m <= p:
            temp += dp[p - m]
    dp[p] += temp % mod

print(dp[n-1])
