#!/usr/bin/env python3

import sys
input=sys.stdin.readline

mod=998244353

n,k=map(int,input().split())
arr=[list(map(int,input().split()))+[i] for i in range(k)]
dp=[0]*(n+1)
dp[1]=1
sums=[0]*k
for i in range(2,n+1):
  for l,r,j in arr:
    if l>i:
      continue
    elif l<=i<=r:
      sums[j]+=dp[i-l]
    else:
      sums[j]-=dp[i-r-1]
      sums[j]+=dp[i-l]
    sums[j]%=mod
  for j in range(k):
    dp[i]+=sums[j]
print(dp[n]%mod)