def main():
    n, k = map(int, input().split())
    ds = set()
    for _ in range(k):
        l, r = map(int, input().split())
        ds = ds | {i for i in range(l, r + 1)}
    dp = [0] * (n + 1)
    dp[1] = 1

    for i in range(2, n + 1):
        for d in ds:
            if i - d >= 0:
                dp[i] += dp[i - d]

    print(dp[-1] % 998244353)


if __name__ == "__main__":
    main()
