mod = 998244353
def main():
  n, k =  map(int, input().split())
  query= []
  for i in range(k):
    query.append(list(map(int, input().split())))
  dp = [0]*(n + 1)
  dp[1] = 1
  for i in range(2, n+1):
    dp[i] += dp[i-1]
    for lr in query:
      if i-lr[0] <= 0:
        continue
      else:
        dp[i] += dp[i-lr[0]]-dp[max(0, i-lr[1]-1)]
        dp[i] %= mod
  print((dp[n]-dp[n-1])%mod)
  
if __name__ == "__main__":
  main()