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 = []

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(n):
    if not cnt_list[i] == 0:
        for j in range(len(s_list)):
            if i+s_list[j] < n:
                cnt_list[i+s_list[j]] += cnt_list[i]

print(cnt_list[n-1] % mod)