N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

dp = [[0 for _ in range(N)] for _ in range(N + 1)]
dp[0][1] = 1

min_interval = min(i for l, r in LR for i in range(l, r + 1))
max_step = (N - 1 + (min_interval - 1)) // min_interval

ans = 0
prev_nodes = [1]
for step in range(1, max_step + 1):
    for i in range(N):
        for l, r in LR:
            for d in range(l, r + 1):
                if N < i + d:
                    continue
                elif N == i + d:
                    ans = (ans + dp[step - 1][i]) % 998244353
                else:
                    dp[step][i + d] += dp[step - 1][i]

print(ans)
