# -*- coding: utf-8 -*-
# map(int, input().split())
mod = 998244353

N, K = map(int, input().split())
kukans = []

for k in range(K):
    L, R = map(int, input().split())
    kukans.append([L,R])

kukans = list(sorted(kukans, key=lambda x:x[0]))

ruiseki_dp = [0]
for i in range(1,N+1):
    if i == 1:
        ruiseki_dp.append(1)
    else:
        # たどり着くためにできるマスの動き
        able_kukans = []
        for L,R in kukans:
            if R <= i-1:
                able_kukans.append([L,R])
            elif L <= i-1 < R:
                able_kukans.append([L,i-1])
                break
            else: # i-1 < L
                break
        
        next_dp = 0
        for L, R in able_kukans:
            next_dp = (next_dp+ruiseki_dp[i-L]-ruiseki_dp[i-R-1])%mod

        ruiseki_dp.append((ruiseki_dp[-1]+next_dp)%mod)
    
print(ruiseki_dp[-1]-ruiseki_dp[-2])