N,K = map(int, input().split())
import numpy as np
MOD = 998244353

lst = np.zeros((N+1), int)
for _ in range(K):
  l, r = map(int, input().split())
  #for i in range(l, r+1):
  lst[l:r+1] = 1
    
#print(lst)

dp = np.zeros((N), int)
dp[0] = 1

for i in range(N):
  dp[i:] += lst[:N-i] * dp[i] % MOD
  #print(dp)
  #print(dp[i:], lst[:N-i])
   
print(dp[N-1] % MOD)