import sys

sys.setrecursionlimit(2*10**5)
MOD = 998244353
LR = []
memo = {}

def solve(n):
    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)
                answer %= MOD
    memo[n] = answer
    return answer


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