MOD=998244353
N,K=[int(s) for s in input().split()]
ls=[0 for _ in range(N)]
lssum=[0 for _ in range(N)]
ls[0]=1
lssum[0]=1

sections=[[int(s) for s in input().split()] for _ in range(K)]
sections.sort()

for i in range(1,N):
  for sec in sections:
    if sec[0]>i:
      continue
    else:
      l=sec[0]
      r=min([i,sec[1]])
      ls[i]=(ls[i]+lssum[i-l]-lssum[i-r-1])%MOD
  lssum[i]=(lssum[i-1]+ls[i])%MOD
print(ls[N-1])
      