from sys import stdin
input = stdin.buffer.readline

def main():
    mod = 998244353
    n, k = map(int, input().split())

    lr = [(0, 0)] * k
    for i in range(k):
        l, r = map(int, input().split())
        lr[i] = (l, r+1)

    # Cumulative Sum
    dp = [0] * n
    dp[0] = 1
    dp[1] = -1
    for i in range(n):
        dp[i] += dp[i-1]
        dp[i] %= mod
        for l, r in lr:
            if i + l < n:
                dp[i + l] += dp[i]
                dp[i + l] %= mod
                if i + r < n:
                    dp[i + r] -= dp[i]
                    dp[i + r] %= mod

    print(dp[n-1])

main()