mod = 998244353
N, K = map(int, input().split())
L = [0] * K
R = [0] * K
for i in range(K):
      L[i], R[i] = map(int, input().split())

Move = []

for i in range(K):
    value = L[i]
    while True:
        Move.append(value)
        value += 1
        if value > R[i]:
            break
#Move.sort()
# print(Move)

DP = [0] * N
DP[0] = 1

for i in range(1, N):
    for m in Move:
        if i - m >= 0:
            DP[i] += DP[i - m]
            DP[i] = DP[i] % mod
        # else:
        #     break
print(DP[N - 1])
