N,K = map(int,input().split())
S = set()
for _ in range(K):
  a,b = map(int,input().split())
  for i in range(a,b+1):
    S.add(i)
    
def dfs(n):
  if n == N:
    return 1
  elif n > N:
    return 0
  else:
    cnt = 0
    for i in S:
      cnt += dfs(n+i)
      
    return cnt

ans = dfs(1) % 998244353
print(ans)