MOD = 998244353


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

    SN = []
    for _ in range(K):
        L, R = map(int, input().split())
        SN.append((L, R))

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

    for n in range(2, N + 1):
        for S in SN:
            L, R = S
            L =  n - L
            R = n - R

            print("n={},L={},R={}".format(n, L, R))
            print("n-R={}, n-L={}".format(n - R, n - L))
            dp[n] = (dp[n] + sum(dp[(n - R):(n - L)+1])) % MOD
            print(dp)

    print(dp[N])


main()
