n, k = map(int,input().split())
grid = []
for i in range(k):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)

S = []

for i in range(k):
    for j in range(grid[i][1]-grid[i][0]+1):
        S.append(grid[i][0]+j)
S.sort()
#print(S)
array = [1]

for i in range(2,n+1):
    count = 0
    for j in S:
        if i - j > 0:
            count += array[i-j-1]
            count = count % 998244353
            #print(i,j,array[i-j-1])
    array.append(count)
    #print(i,count)

print(array[n-1])
