n,k = map(int,input().split())
ns = []
for i in range(k):
    l, r = map(int,input().split())
    for k in range(l, r+1):
        ns.append(k)
arr = [0 for i in range(n)]
arr[0] = 1
for i in range(n):
    for j in ns:
        if i + j < n:
            arr[i + j] += arr[i]
print(arr[n-1] % 998244353)