import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal
# from fractions import Fraction
# sys.setrecursionlimit(100000)
mod = 998244353
INF=float('inf')
 
n,k=mdata()
lis=[]
dp=[0]*(n)
dp[0]=1
for i in range(k):
    l,r=mdata()
    for j in range(l,r+1):
        lis.append(j)
lis.sort()
for i in range(1,n):
    for j in lis:
        if j>i:
            break
        dp[i]=(dp[i]+dp[i-j])%mod
out(dp[-1])