n, k = map(int, input().split())
s = []
for i in range(k):
  l, r = map(int, input().split())
  for j in range(l, r+1):
    s.append(j)

dp = [-1 for i in range(n+1)]
    
def dfs(A):
  if (A < 0):
    return 0
  if (A == 0):
    return 1
  
  if (dp[A] >= 0):
    return dp[A]
 
  ans = 0
  for i in s:
    ans += dfs(A - i)
    ans %= 998244353
 
  dp[A] = ans
  return ans
if(n == 1):
  if(1 in s):
    print(1)
  else:
    print(0)
  exit()
    
print(dfs(n-1))

