n, k = map(int,input().split())
lst = []
lst2 = [0, 1]
for i in range(k):
    l, r = map(int,input().split())
    for j in range(l, r + 1):
        lst.append(j)

def count(n, x, y):
    ans = 0
    for i in range(len(x)):
        if (n - x[i] <= 0):
            pass
        else:
            ans = ans + y[n - x[i]]
    y.append(ans%998244353)

for i in range(n + 1):
    if (i != 0 and i != 1):
        count(i, lst, lst2)

print(lst2[n])