import sys


def main():

    input = sys.stdin.readline

    N,K = map(int,input().split())

    S = set()

    mod = 998244353

    for i in range(K):
        l,r = map(int,input().split())

        for i in range(l,r+1):
            S.add(i)

    masu = [0] * N

    masu[0] = 1

    for i in range(N):
        for j in S:
            if i+j < N:
                masu[i+j] += masu[i]
                masu[i+j] %= mod
            else:
                break


    print(masu[N-1] % mod)


if __name__ == "__main__":
    main()