# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 998244353
N, K = map(int, readline().split())
data = []
for _ in range(K):
    L,R = map(int, readline().split())
    data.append((L,R))
    
data = sorted(data)

dp = [0]*(N+1)
dp[1] = 1
for i in range(2,N+1):
    for k in range(K):
        L,R = data[k]
        if i-L >= 0:
            dp[i] += sum(dp[i-R:i-L+1])%MOD

print(dp[N])