# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))
def cum_sum(lst):
    cums = [0] * (len(lst)+1)
    cums[1] = lst[0]
    for i in range(2,len(lst)+1):
        cums[i] = cums[i-1] + lst[i-1]
    return cums

n,k = mp()
mod = 998244353
s = [0]*(n+3)
for i in range(k):
    a,b = mp()
    s[a] += 1
    s[b+1] -= 1
s = cum_sum(s)[1:]
se = set()
for i in range(n+1):
    if s[i] > 0:
        se.add(i)
se = list(se)
dp = [0]*(n+1)
dp[1] = 1
for i in range(2, n+1):
    for j in range(len(se)):
        if i - se[j] > 0:
            dp[i] += dp[i-se[j]]
            dp[i] %= mod
print(dp[n])


