import sys
input = sys.stdin.readline

N,K = (int(x) for x in input().rstrip('\n').split())
As = []
n = [x for x in range(1,N+1)]
for _ in range(K):
  L,R = (int(x) for x in input().rstrip('\n').split())
  As.extend(n[L-1:R])
res_d = {0:1}
for i in range(1,N):
  res = 0
  for k,v in res_d.items():
    if any(k+x==i for x in As):
      res += v
  res_d[i] = res%998244353
print(res_d[N-1])
