mod = 998244353
n,k = map(int, input().split()) 
num_list = [list(map(int, input().split())) for _ in range(k)]
cnt_list = [0]*n
cnt_list[0] = 1
s_list = []
set_list = [0]*n

for i in range(len(num_list)):
    if num_list[i][0] == num_list[i][1]:
        s_list.append(num_list[i][0])
    else:
        for j in range(num_list[i][0],num_list[i][1]+1):
            s_list.append(j)

for i in range(len(s_list)):
    set_list[s_list[i]] = 1

for i in range(n):
    cnt_list = [x * cnt_list[i] + y for (x, y) in zip(set_list, cnt_list)]
    set_list.insert(0,0)
    set_list.pop(n)

print(cnt_list[n-1]%mod)