def once(S,m,n):
    a=[]
    for i in range(len(S)):
        for j in range(len(m)):
            a+=[m[j]-S[i]]
    a.sort(reverse=True)
    for j in range(len(a)):
        if a[j]==1:
            n+=1
    for j in range(len(a)):
        if a[len(a)-1]<=1:
            a.remove(a[len(a)-1])
    m=a
    return m,n
def route(N,S):
    n=0
    m=[]
    for j in range(len(S)):
        m+=[N-S[j]]
    for i in range(len(m)):
        if m[i]==1:
            n+=1
    m.sort(reverse=True)
    for j in range(len(m)):
        if m[len(m)-1]<=1:
            m.remove(m[len(m)-1])
    while m!=[]:
        k=[once(S,m,n)[0],once(S,m,n)[1]]
        m=k[0]
        n=k[1]

    return n%998244353
Na,Ka=input().split()
N=int(Na)
K=int(Ka)
S=[]
for i in range(K):
    x,y=input().split()
    S+=[i for i in range(int(x),int(y)+1)]
print(route(N,S))
