#D
N,K=map(int,input().split())
p=998244353
L=[0]*K
R=[0]*K
C=[0]*K
allnum=set(i for i in range(1,N+1))
mov=set()
for i in range(K):
    L[i],R[i] = map(int,input().split())
    for i in range(L[i],R[i]+1):
        mov.add(i)
    #C[i] = [L[i],R[i]]
#C.sort()
mov2=allnum-mov

if len(mov)<len(mov2):
    dp = [0]*(N+1)
    dp[1]=1
    for i in range(2,N+1):
        for m in mov:
            if i-m>=1:
                dp[i] += dp[i-m]
                dp[i] %= p
else:
    dp = [0]*(N+1)
    dp[1]=1
    summ=0
    for i in range(2,N+1):
        summ += dp[i-1]
        summ %=p
        cant=0
        for m in mov2:
            if i-m>=1:
                cant += dp[i-m]
                cant %= p
        dp[i]=summ-cant
        #print(dp[i],summ)
    
print(dp[-1])