def resolve():
    n, k = map(int, input().split())
    S = []
    for _ in range(k):
        l1, r1 = map(int, input().split())
        S.append(l1)
        S.append(r1)
    S = list(set(S))

    dp = [[0 for i in range(n + 1)] for j in range(len(S) + 1)]
    for i in range(len(S) + 1):
        dp[i][1] = 1
    for i in range(1, len(S) + 1):
        for j in range(2, n + 1):
            if j - S[i - 1] >= 0 and dp[i][j - S[i - 1]] > 0:
                dp[i][j] = dp[i][j - S[i - 1]] + dp[i - 1][j]
            else:
                dp[i][j] = dp[i - 1][j]

    print(dp[-1][n] % 998244353)

resolve()
