n,k = map(int,input().split())
num = []

for i in range(k):
    l,r = map(int,input().split())
    for j in range(l,r+1):
        num.append(j)

A = [1]
for i in range(1,n):
    a = 0
    for j in num:
        if i-j > -1:
            a += A[i-j]
        else:
            a += 0
    A.append(a)
print(A[n-1]%998244353)
