import itertools
import bisect

mod = 998244353

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

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

for i in range(k):
    l, r = map(int,input().split())
    area[l] += 1
    if r+1 <= n:
        area[r+1] -= 1
        

area = list(itertools.accumulate(area))    
able = [i for i,v in enumerate(area) if v==1]

for i in range(1,n+1):
    for d in able:
        if i-d <= 0:
            break
        dp[i] = (dp[i]+dp[i-d])%mod

print(dp[n]%mod)