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()
    MOD = 998244353
    for start, end in LR:
        for i in range(start, end + 1):
            S.add(i)
    M = dict()
    M[1] = 1
    for i in range(1, N + 1):
        calc(i, S, M)
    print(M[N] % MOD)


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


if __name__ == "__main__":
    main()
