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

S = list()
for lr in LR:
    for i in range(lr[0], lr[1]+1):
        S.append(i)

dp = [0]*(N+1) # dp[i] : iに行く方法
dp[1] = 1

memo = list()

for i in range(1, N+1):
    # for s in S:
    #     if i + s <= N:
    #         dp[i + s] += dp[i]
    #         dp[i + s] %= MOD
    for m in memo:
        # l = m[1]
        # r = m[2]
        if m[1] <= i and i <= m[2]:
            dp[i] += m[0]
            dp[i] %= MOD
    
    for lr in LR:
        memo.append([dp[i], lr[0] + i, lr[1] + i])
    
print(dp[N])