n,k = map(int, input().split())
s = set()
for i in range(k):
  l,r = map(int, input().split())
  for _ in range(l,r+1):
    s.add(_)
a = [0]*(2*10**5+1)
a[1] = 1
for i in range(2*10**5):
  for d in s:
    if i+d <= 2*10**5:
      a[i+d] += a[i]%998244353
    else:
      break
print(a[n]%998244353)