
def solve():
    MOD = 998244353
    N, K = map(int, input().split())
    S = set()
    for i in range(K):
        _l, _r = map(int, input().split())
        _s = set(list(range(_l, _r+1)))
        S |= _s

    # dp[i] : iに到達する経路数
    dp = [0] * (N+1)
    dp[1] = 1
    for i in range(2, N+1):
        for d in S:
            if i-d > 0:
                dp[i] = (dp[i] + dp[i-d]) % MOD
    print(dp[N])


solve()
