import sys
def input(): return sys.stdin.readline().rstrip()

N, K = map(int, input().split())

L = []
for i in range(K):
    l, r = map(int, input().split())
    L.append((l,r))

L.sort()

dp = [0] * (N+1)
dp[1] = 1

for i in range(2,N+1):
    count = 0
    for l,r in L:
        if l >= i:
            break
        elif l < i and i - r > 1:
            count += dp[i-l] - dp[i-r-1]
        else:
            count += dp[i-l]
    dp[i] = dp[i-1] + count

print((dp[N] - dp[N-1])% 998244353)