n,k = map(int, input().split())
hani = [0 for i in range(n)]
kumi = [-1 for i in range(n)]
min = n
for i in range(k):
    l,r = map(int,input().split())
    if l < min:
        min = l
    for j in range(l-1,r):
        hani[j] = 1
for j in range(min-1):
    kumi[j] = 0
kumi[min-1] = 1

def countt(n,hani,kumi):
    an = 0
    for i in range(0,n-1):
        if hani[i] == 1:
            if n-i-2 >= 0:
                if kumi[n-i-2] == -1:
                    kumi = countt(n-i-1,hani,kumi)
                an += kumi[n-i-2]
            else:
                break
    kumi[n-1] = an
    return kumi

kumi = countt(n,hani,kumi)
ans = kumi[-1]
print(ans % 998244353)