N, K = map(int, input().split())
S = []
for _ in range(K):
    x, y = map(int, input().split())
    for i in range(x, y+1):
        S.append(i)
ALL = [0] * (N)
ALL[0] = 1
for i in range(N):
    for k in S:
        if k > i:
            next
        else:
            ALL[i] += ALL[i-k]
            ALL[i] = ALL[i] % 998244353
print(ALL[N-1])