n,k=map(int,input().split())
S = set()
for i in range(k):
  l,r=map(int,input().split())
  S = S|set(range(l,r+1))
S=list(S)
ans = [0]*n
ans[0]=1
for i in range(n):
  for s in S:
    if i+s < n:
      ans[i+s] += ans[i]
print(ans[n-1]%998244353)