n,m= list(map(int,input().split()))
s = []
for _ in range(m):
  p,q = list(map(int,input().split()))
  for i in range(p,q+1):
    s.append(i)
ways = [1] + [0 for _ in range(n-1)]
for i in range(1,n):
  for x in s:
    if i -x >=0:
      ways[i] += ways[i-x]
print(ways[-1]%998244353)