
import numpy as np

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



move_list = []
checker = np.zeros(N+1 ,dtype = int)
for LR in LRs:
    for i in range(LR[0], LR[1]+1):
        checker[i] = 1

for index, check in enumerate(checker):
    if(check == 1):
        move_list.append(index)

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

#for i in range(1, N+1):
#    for j in move_list:
#        if(i < j):
#            break
#        dp[i] = (dp[i] +dp[i-j]) % 998244353

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.extend(p_array)
        mae_zero.extend(usiro_zero)
#        print(mae_zero)
        dp += np.array(mae_zero)
#        print(dp[1:N+1])

print(dp[N] % 998244353)
