N, K = map(int, input().split())
A = [False]*(N+1)
for _ in range(K):
    l, r = map(int, input().split())
    for a in range(l, r+1):
        A[a] = True

S = []
for i in range(1,N+1):
    if A[i]:
        S.append(i)
        
mod = 998244353
        
table = [0]*N
table[0] = 1

for i in range(N):
    for s in S:
        if i + s < N:
            table[i+s] += table[i]
            table[i+s] %= mod
            
print(table[N-1]%mod)