import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 998244353
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
lr = [IL() for i in range(K)]
lr.sort()

dp = [0]*(N+1)
dp[1] = 1
data = [0]*(N+1)
data[1] = 1

for i in range(2,N+1):
  tmp = 0
  for l,r in lr:
    if tmp >= r:
      continue
    elif l <= tmp < r:
      l = tmp+1
    if 1 <= i-l:
      dp[i] += data[i-l] - data[max(i-r-1, 0)]
  data[i] = (data[i-1] + dp[i]) %mod
print(dp[N])