import sys
input = sys.stdin.buffer.readline
N, K = map(int, input().split())
A = [tuple(map(int, line.split())) for line in sys.stdin.buffer.readlines()]
A.sort()
mod = 998244353

acc = [0]*(N+5)
acc[0] = 1
for i in range(1, N+1):
    cum = 0
    for l, r in A:
        if i-l < 0:
            break
        p, q = max(0, i-r), max(0, i-l)
        cum += acc[q]-acc[p-1]
    acc[i] = (cum+acc[i-1]) % mod

print((acc[N-1]-acc[N-2]) % mod)
