n,k = map(int, input().split())
hani = [0 for i in range(n)]#i-1がふくまれているか
kumi = [-1 for i in range(n+1)] #iマス目に行く通り
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
kumi[0] = 1
if min > 1:
    for i in range(1,min):
        kumi[i] = 0
kumi[min] = 1

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

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