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

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

print(dp[n] % mod)
