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

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

for step in range(1, N + 1):
    for i in range(N):
        for l, r in LR:
            for d in range(l, r + 1):
                if N < i + d:
                    continue
                else:
                    dp[step][i + d] += dp[step - 1][i]

ans = 0
for i in range(N + 1):
    ans = (ans + dp[i][N]) % 998244353

print(ans)
