def f(L,n):
    x=0
    if n<1:
        return 0
    if n==1:
        return 1
    if n>1:
        for i in range(len(L)):
            x+=f(L,n-L[i])
            x=x%998244353      
        return x
def f2(L,a,b):
    for i in range(min(a,b),max(a,b)+1):
        L[i]=1
    return L
N,K=map(int,input().split())
M=[]
for i in range(K):
    l=list(map(int,input().split()))
    M.append(l)
L=[0 for i in range(N+1)]
for i in range(K):
    f2(L,M[i][0],M[i][1])
X=[]
for i in range(N+1):
    if L[i]==1:
        X.append(i)
print(f(X,N)%998244353)


