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

MOD = 998244353

PAT = []
for _ in range(K):
  l,r = map(int, input().split())
  PAT.append((l,r))
  
IMOS = [0] * (2*N+10)
IMOS[1] = 1
for i in range(0,N):
  for l,r in PAT:
    IMOS[i+l] += IMOS[i]
    IMOS[i+r+1] -= IMOS[i]
  #print(i, IMOS)
  IMOS[i+1] += IMOS[i]
  IMOS[i+1] % MOD
  
print((IMOS[N] - IMOS[N-1]) % MOD)
    