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

for i in range(K):
    temp=list(map(int,input().split()))
    LR.append(temp)
    for j in range(temp[0],temp[1]+1):
        move.append(j)
move.sort()
l=len(move)
ishere={0:1}

def dp(N):    
    if N<0:    
        return 0
    elif N==0:
        return 1
    elif N in ishere.keys():
        return ishere[N]
    else:
        temp=0
        for j in range(l):
            temp+=dp(N-move[j])
            ishere[N]=temp
        return temp    
ans=dp(N-1)%998244353
print(ans)