n,k=map(int, input().split())
MOD = 998244353
a = [0]*(n+1)

for i in range(k):
    l,r=map(int, input().split())
    a[l-1] += 1
    a[r] -= 1

now = 0
s = []
for i in range(n):
    now += a[i]
    if(now > 0): s.append(i+1)

ans = [0]*n
ans[0] = 1
for i in range(0, n):
    for j in s:

        if(j+i < n):
            ans[j+i] += ans[i]
            ans[j+i] = ans[j+i] % MOD

print(ans[-1])