import itertools

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

mod = 998244353

m_list = []

for _ in range(k):
    l, r = map(int, input().split())
    t_list = list(range(l,r+1))
    m_list.append(t_list)

m_list = list(itertools.chain.from_iterable(m_list))

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

for i in range(n):
    for j in range(len(m_list)):
        dp[i] += dp[i-m_list[j]]

print(dp[n-1] % mod)