mod = 998244353
N,K = map(int,input().split())

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

dp = [0]*N
dp[0] = 1
dp[D[0][0]] = 1

for n in range(D[0][0],N-1):
    dp[n+1] = dp[n]
    for i in range(K):
        L,R = D[i]
        if n-L+1>=0:
            dp[n+1] += dp[n-L+1]
        if n-R+1>0:
            dp[n+1] -= dp[n-R]
        dp[n+1] %= mod
print(dp[N-1])