import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
mod = 998244353
dp = [0]*N
dp[0] = 1

ok = [0]*(N+1)
for _ in range(K):
    l, r = mapint()
    ok[l-1] += 1
    ok[r] -= 1
from itertools import accumulate
ok = list(accumulate(ok))
lis = [i for i in range(1, N+1) if ok[i-1]]
for i in range(N):
    for d in lis:
        if i-d>=0:
            dp[i] += dp[i-d]
            dp[i] %= mod

print(dp[-1])