#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    mod = 998244353
    N, K = iim()
    it = map(int, sys.stdin.read().split())
    A = [0] * N
    A[0] = 1

    B = []
    for l, r in zip(it, it):
        for x in range(l, r+1):
            B.append(x)

    B.sort()
    for i in range(N-1):
        if A[i] == 0:
            continue
        for j in B:
            k = i + j
            if k >= N:
                break
            A[k] = (A[k] + A[i]) % mod

    print(A[-1])


if __name__ == "__main__":
    resolve()
