def input_int():
    return(int(input()))

def input_int_list():
    return(list(map(int,input().split())))

def input_int_map():
    return(map(int,input().split()))

def run():
    n, k = input_int_map()

    ranges = []
    for _ in range(k):
        l, r = input_int_map()
        ranges.append((l, r))

    dp = [0] * n
    dp[0] = 1
    dp[1] = -1

    for i in range(0, n):
        dp[i] = dp[i - 1]

        for l, r in ranges:
            if i + l < n:
                dp[i + l] += dp[i]

            if i + r + 1 < n:
                dp[i + r + 1] -= dp[i]

    result = dp[-1] % 998244353
    print(result)

run()
