def resolve():
    import sys
    input = sys.stdin.readline
    mod = 998244353
    n, k = map(int, input().split())
    dp = [0] * n
    dp[0] = 1
    s = [tuple(map(int, input().split())) for _ in range(k)]
    total = 0
    for i in range(n - 1):
        total = (total + dp[i]) % mod
        for l, r in s:
            if i + l < n:
                dp[i + l] += total
                if i + r + 1 < n:
                    dp[i + r + 1] -= total
    print(dp[-1])


if __name__ == '__main__':
    resolve()
