
MOD = 998244353

def solve(N, LR, memo):
    if N == 1:
        return 1
    if N in memo:
        return memo[N]
    answer = 0 
    for l, r in LR:
        for d in range(l, r+1):
            if N-d > 0:
                answer += solve(N-d, LR, memo)
                answer %= MOD
    memo[N] = answer
    return answer


LR = []
N, K = map(int, input().split())
for i in range(K):
    L, R = map(int, input().split())
    LR.append([L, R])
memo = {}
print(solve(N, LR, memo))