
N,K = map(int,input().split())
dp = [0 for _ in range(3*N)]
dp[0] = 1
S_left = []
S_right = []
for i in range(K):
    l,r = map(int,input().split())
    S_left.append(l)
    S_right.append(r)
plus = 0
for j in range(N):
    plus += dp[j]
    for k in range(K):
        dp[S_left[k]+j]+= plus
        dp[S_left[k]+j]%=998244353
        dp[S_right[k]+j+1]-= plus
        dp[S_right[k]+j+1]%=998244353
dp_cum = [1]
print(dp[N-1]%998244353)
