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


def countt(n,hani,kumi):
    if n == 1:
        if hani[0] == 1:
            kumi[0] = 1
        else:
            kumi[0] = 0
    else:
        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[-1]
print(ans % 998244353)
