import numpy as np

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

dp = np.zeros(N*2+2, dtype = int)
dp[1] = 1

for i in range(1, N+1):
    atai = dp[i]
    for LR in LRs:
#        p_array = ([atai] * (LR[1] - LR[0] + 1))
#        mae_zero = ([0] * (LR[0] + (i - 1) + 1))
#        usiro_zero = ([0] * (N*2 - (i - 1) - LR[1]))

        mae_zero = np.zeros(LR[0] + i , dtype = "int32")
        usiro_zero = np.zeros(N*2 - (i - 1) - LR[1], dtype = "int32")
        p_array = np.full((LR[1] - LR[0] + 1), atai, dtype = "int32")

        tasu_array = np.concatenate([mae_zero, p_array, usiro_zero])
        dp = (dp + tasu_array) % 998244353

print(dp[N] % 998244353)