import collections
import math
import sys
sys.setrecursionlimit(10**7)
inf=998244353


N,K=map(int,input().split())
SS=[]

for i in range(K):
    s1,s2=map(int,input().split())
    for j in range(s1,s2+1):
        SS.append(j)

# Driver program to test above function 

table = [0 for k in range(N-1)] 

for s in SS:
    if s<N-1:
        table[s-1]+=1
for i in range(0,N-1):
    for s in SS:
        if i+s<N-1:
            table[i+s]+=table[i]
            table[i+s]%=inf
print(table[-1]%inf)
