N,K = map(int,input().split())
num_list = [0] * N
num_list_pure = []
num_list[0] = 1
for i in range(K):
    L,R = map(int,input().split())
    for j in range(L,R+1):
        num_list_pure.append(j)
num_list_pure.sort()
for i in range(1,N):
    for j in range(len(num_list_pure)):
        num_tmp = num_list_pure[j] 
        if num_tmp <= i:
            num_list[i] += num_list[i - num_tmp]
        else:
          break
print(num_list[N-1] % 998244353)