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

div = set()
for _ in range(K):
  l,r = map(int,input().split())
  for i in range(l,r+1):
    div.add(i)
min_step = min(div)
dp = [-1]*N
dp[0] = 1
def calc(i):
  if dp[i] != -1: return dp[i]
  if i < min_step: dp[i]=0; return dp[i]

  dp[i] = 0
  for j in div:
    if j > i: continue
    dp[i-j] = calc(i-j)
    dp[i] = (dp[i] + dp[i-j])%mod
  dp[i] %= mod
  return dp[i]

print(calc(N-1)%mod)
