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

    dp = [0]*N
    dp[0] = 1
    for i in range(N):
        for d in S:
            if d > i:
                break
            dp[i] += dp[i-d] % 998244353
    print(dp[N-1] % 998244353)

resolve()