def count(n, S, memo):
    if n < 0:
        return 0
    elif n == 1:
        return 1
    elif memo[n] > -1:
        return memo[n]
    else:
        x = 0
        for s in S:
            x += count(n - s, S, memo)
        memo[n] = x
        return memo[n]


N, K = map(int, input().split())
S = set()
for i in range(K):
    L, R = map(int, input().split())
    S = S | (set(range(L, R+1)))
memo = [-1] * (N + 1)
print(count(N, S, memo) % 998244353)