def readInt():
    return int(input())
def readList():
    return list(map(int,input().split()))
def readMap():
	return map(int,input().split())
def readStr():
    return input()
inf=float('inf')
mod = 998244353
import math
def solve(N,S):
    """
    Tak begins in cell=1 and wants to move to cell=N.  All cells are along a line and 1,2,...,N is from left to right.
    Args:
        N(int):  The number of cells.
        S(list):  The set containing all integers in the non-intersecting intervals.

    Returns:
        int:  The number of ways for Tak to go from cell=1 to cell=N.
    """
    dp=[0]*(N+1)
    dp_sums=[0]*(N+1)
    dp[1]=dp_sums[1]=1
    
    for i in range(2,N+1):
        for le,ri in S:
            if i>= ri+1:
                dp[i]+=dp_sums[i-le]-dp[i-ri-1]
                dp_sums[i]=dp_sums[i-1]+dp[i]
            elif i>le and i<ri+1:
                dp[i]+=dp_sums[i-le]
                dp_sums[i]=dp_sums[i-1]+dp[i]
            elif i<=le:
                dp_sums[i]=dp_sums[i-1]+dp[i]
        dp[i]%=mod
        dp_sums[i]%=mod
    return dp[N]

N,K=readMap()
S=[]
for _ in range(K):
    S.append(readList())
print(solve(N,S))