MOD=998244353
N,K=map(int, input().split())
s=set()
for i in range(K):
    l,r=map(int, input().split())
    s.add(l)
    s.add(r)
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])
    n[i+1] = p

print(n[-1]%MOD)