n, k= map(int, input().split())
l = [None] * n
r = [None] * n
for i in range(k):
    l[i], r[i] = map(int, input().split())

x = [None] * n
x[0] = 1
for i in range(n):
    if x[i] is None:
        continue
    for j in range(k):
        for p in range(l[j], r[j] + 1):
            if i + p >= n:
                break
            if x[i + p] is None:
                x[i + p] = x[i]
            else:
                x[i + p] += x[i]
            x[i + p] %= 998244353
if x[n - 1] is None:
    print(0)
else:
    print(x[n - 1])