import sys
def input():
    return sys.stdin.readline()[:-1]
ra = range

def main():
    N, K = map(int, input().split())
    MOD = 998244353
    cand = set()
    for _ in range(K):
        L, R = map(int, input().split())
        A = set(ra(L,R+1))
        cand |= A

    dp = [0] * (N + 5)
    dp[0] = 1
    for i in range(N):
        for j in cand:
            if i + j <= N:
                dp[i+j] += dp[i]
                dp[i+j] %= MOD
            else:
                break

    print(dp[N-1])    




if __name__ == "__main__":
    main()