MOD=998244353
N,K=map(int, input().split())
s=set()
for i in range(K):
    l,r=map(int, input().split())
    for i in range(l,r+1):
        s.add(i)
a = list(s)
a.sort()
n = [0]*(N)
n[0]=1
for i in range(N-1):
    p = 0
    for j in a:
        if i + 1 >= j:
            p = (p+n[i-j+1]) % MOD
    n[i+1] = p % MOD
print(n[-1])