import sys
input = sys.stdin.readline

MOD = 998244353


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()
    M[1] = 1
    for i in range(2, N + 1):
        M[i] = sum([M[i - s] for s in S if (i - s > 0)]) % MOD
    print(M[N])


if __name__ == "__main__":
    main()
