def inc(v):
  for x in lr:
    if (v>=x[0]) & (v<=x[1]):
      return True
  return False

n,k = list(map(int,input().split()))
lr = [list(map(int,input().split())) for _ in range(k)]
lrmax = max( [i[1] for i in lr] )

x = [1]
for i in range(1,n):
  val = 0
  for j in range(1,min(i,lrmax) + 1):
    if inc(j):
      val += x[-j] % 998244353
  x.append(val)
print(x[-1])