N, K = [int(v) for v in input().split()]

link = []
for k in range(K):
    L, R = [int(v) for v in input().split()]

    for i in range(L, R+1):
        link.append(i)

link.sort()
#link.reverse()
#print(link)

count = [0, 1]

for i in range(2, N + 1):
    v = 0
    for l in link:
        if i < l:
            break
        v += count[i - l]
    count.append(v)

print(count[-1] % 998244353)
