N,K = map(int,input().split())
N-=1
mvs = set()
mods = 998244353
dps = [0]+[0 for i in range(N)]

for _ in range(K):
  a,b = map(int,input().split())
  for k in range(a,b+1):
    mvs.add(k)

for k in mvs:
  if k <= N:
    dps[k]+=1

for i in range(2,N+1):
  for k in mvs:
    dps[i] += dps[i-k] % mods if i-k >0 else 0
print(dps[N]%mods)