def main():
    MOD = 998244353
    n,k = map(int,input().split())
    LR = []
    for _ in range(k):
        LR.append(tuple(map(int,input().split())))
    
    dp = [0]*(n+1)
    dp[1] = 1
    for i in range(1,n):
        temp = 0
        for l,r in LR:
            ll = max(i+1 - r - 1, 0)
            rr = max(i+1 - l, 0)
            temp+=dp[rr]-dp[ll]
        dp[i+1] = (dp[i] + temp)%MOD
    
    print((dp[n]-dp[n-1])%MOD)
main()