def fun(a, n):   
    count = [0 for i in range(n)]
    count.insert(0,1)
    for x in range(1, n + 1):
        for c in a:
            if (x-c >= 0):
                count[x] += count[x-c]
    return count[n]%998244353

n,k = map(int,input().split())
s = set()
for i in range(k):
    l,m = map(int,input().split())
    for i in range(l,m+1):
        s.add(i)
arr = list(s)
print(fun(arr,n-1))