import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,K = MI()
LR = [tuple(MI()) for i in range(K)]
mod = 998244353

dp = [0]*(N+1)  # dp[i] = マス1に行く方法の個数 + マス2に行く方法の個数 + … + マスiに行く方法の個数
dp[1] = 1

for i in range(2,N+1):
    dp[i] = dp[i-1]
    for j in range(K):
        l,r = LR[j]
        dp[i] += dp[max(i-l,0)]-dp[max(i-r-1,0)]
        dp[i] %= mod

print((dp[N]-dp[N-1]) % mod)
