n, k = map(int, input().split())
a = set()
for i in range(k):
  l, r = map(int, input().split())
  for j in range(l, r+1):
     a.add(j)
a = list(a)


x = [0]*n
x[0] = 1

for i in range(n):
  for d in a:
    if i + d < n and x[i] != 0:
      x[i+d] += x[i]
   
print(x[n-1] % 998244353)