import sys
import numpy as np
input = sys.stdin.readline

mod = 998244353

n, k = map(int, input().split())

s = []
for _ in range(k):
    l, r = map(int, input().split())
    s += list(range(l, r+1))

s = set(s)

dp = np.array([0] * (2 * n))
dp[0] = 1

s = np.array(sorted(list(s)))

for i in range(n):
    if dp[i] == 0:
        continue
    dp[i+s] += dp[i]

print(dp[n-1]%mod)