MOD = 998244353


def main():
    N, K = map(int, input().split())

    S = []
    for _ in range(K):
        L, R = map(int, input().split())
        S += range(L, R + 1)

    dp = [0 for _ in range(N + 1)]
    dp[1] = 1

    for n in range(1, N + 1):
        for s in S:
            if 0 < n - s:
                dp[n] = (dp[n] + dp[n - s]) % MOD

    print(dp[N])


main()
