# -*- coding: utf-8 -*-
N, K = map(int, input().split())

div_num = 998244353
dp = [0 for _ in range(N + 1)]
dp[1] = 1
S_list = []
for i in range(K):
    L, R = map(int, input().split())
    for j in range(L, R + 1):
        S_list.append(j)

S_list.sort()
len_S = len(S_list)
for i in range(2, N + 1):
    for j in range(len_S):
        if i <= S_list[j]:
            break
        dp[i] += dp[i - S_list[j]]

print(dp[N] % div_num)