MOD = 998244353
N, K = map(int, input().split())

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

DP = [0] * (N * 2 + 1)
DP[0] = 1

for index in range(N):
    for A in area:
        for i in range(A[0], A[1] + 1):
            DP[index + i] += DP[index]
            DP[index + i] %= MOD

print(DP[N - 1])
