from sys import stdin
input = stdin.readline
MOD = 998244353


def solve():
    N,K = map(int,input().split())
    step = [tuple(map(int,inp.split())) for inp in stdin.read().splitlines()]
    # @lru_cache(None)
    # def dp(n):
    #     if n == 1:
    #         return 1
    #     res = 0
    #     for a,b in step:
    #         if n <= a:
    #             continue
    #         for i in range(a,b+1):
    #             if n > i:
    #                 res += dp(n-i)
    #     return res % MOD
    #
    # print(dp(N))

    dp = [0] * (N+1)
    dp[1] = 1
    for i in range(2,N+1):
        for a,b in step:
            if i <= a:
                continue
            for j in range(a,b+1):
                if i > j:
                    dp[i] += dp[i-j]
        dp[i] %= MOD
    print(dp[N])



if __name__ == '__main__':
    solve()
