import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    LR = [tuple(map(int, input().split())) for _ in range(K)]
    S = set()
    for start, end in LR:
        for i in range(start, end + 1):
            S.add(i)
    M = dict()
    answer = calc(N, S, M)
    print(answer % 998244353)


def calc(n: int, S: set, M: dict):
    if n <= 0:
        return 0
    if n == 1:
        return 1
    if n in M:
        return M[n]
    result = 0
    for s in S:
        result += calc(n - s, S, M)
    M[n] = result
    return result


if __name__ == "__main__":
    main()
