m = 998244353
N, K = map(int, input().split())

jumps = []
for i in range(K):
    l, r = map(int, input().split())
    jumps += list(range(l, r + 1))

a = [0] * (N + 1)

a[1] = 1
for i in range(2, N + 1):
    for j in jumps:
        if i > j:
            a[i] = (a[i] + a[i - j]) % m
print(a[N])
