import numpy as np

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

MOD = 998244353

lst = [tuple(map(int, input().split())) for _ in range(K) ]
    
#print(lst)

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

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