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

area = []
for i in range(K):
    L, R = map(int, input().split())
    area.append((L, R))

area.sort()
d = [0] * N


def func(pos):
    for a in area:
        for i in range(a[0], a[1]+1):
            if pos - i > -1:
                d[pos] += d[pos-i] % 998244353
            else:
                return


d[0] = 1
for i in range(1, N):
    func(i)

print(d[N-1] % 998244353)
