N, K = map(int, input().split())
LRs = [tuple(map(int, input().split())) for _ in range(K)]
mod = 998244353
    
mem = [0] * (N)
mem[N-1] = 1

for _i in range(N-1):
    i = N-2 - _i
    for l, r in LRs:
        if i+l < N:
            mem[i] += sum(mem[i+l:min(i+r+1, N)])

    mem[i] %= mod

print(mem[0])