n,k = tuple(map(int,input().split()))
boolean = [False for _ in range(n+1)]
for _ in range(k):
  l,r = tuple(map(int,input().split()))
  for num in range(l,r+1):
    boolean[num] = True;
FINAL = [i for i in range(len(boolean)) if boolean[i]]
dp = [0 for _ in range(n+1)]
for i in range(2,n+1):
  for lower in FINAL:  #optimized!
    if boolean[lower]:  #start + lower
      start = i - lower
      if start >= 1:
      	dp[i]+= dp[start]
print(dp[n]%998244353)