def main():
    N, K = map(int, input().split())
    S = []
    while K !=0:
        L, R = map(int, input().split())
        S += [i for i in range(L,R+1)]
        K -= 1
    S.sort()
    A = [1] + [0 for i in range(N + max(s for s in S))]
    for i in range(N):
        for s in S:
            A[i+s] += A[i]
    print(A[N-1] % 998244353)


main()