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 = [1]
for i in range(1,N):
  res.append(sum(res[i-v] for v in As if i-v >= 0)%998244353)
print(res[-1])
