def main():
    N, K = map(int, input().split())
    S = []
    while K !=0:
        L, R = map(int, input().split())
        S += [[L,R]]
        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:
            for t in range(s[0], s[1]+1):
            	A[i+t] += A[i]
    print(A[N-1] % 998244353)


main()