# -*- coding: utf-8 -*-
import sys


def main():
    N,K = list(map(int, sys.stdin.readline().split()))
    LR_list = [ list(map(int, sys.stdin.readline().split())) for _ in range(K) ]

    step = []

    for l,r in LR_list:
        step.extend( list(range(l, r+1)) )
    
    step.sort()
    

    dp = [0] * (N+1)
    dp[1] = 1
    mod = 998244353

    for i in range(N+1):
        for j in step:
            if (i-j) >= 1:
                dp[i] += dp[i-j]
                dp[i] %= mod
            else:
                break
    
    print(dp[-1])


if __name__ == "__main__":
    main()
