(n,_),*s=[[*list(map(int,t.split()))]for t in open(0)]

d=[1,-1]+[0]*2*n

for i in range(n):

  d[i]=(d[i-1]+d[i])%998244353

  for l,r in s:

    d[i+l]+=d[i]

    d[i-~r]-=d[i]

print((d[n-1]))
(n,_),*s=[[*list(map(int,t.split()))]for t in open(0)]

d=[1,-1]+[c:=0]*2*n

for i in range(n):

 c=(c+d[i])%998244353

 for l,r in s:d[i+l]+=c;d[i-~r]-=c

print(c)
(n, _), *s = [[*list(map(int, t.split()))] for t in open(0)]
d = [1, -1] + [0] * 2 * n
for i in range(n):
    d[i] = (d[i - 1] + d[i]) % 998244353
    for l, r in s:
        d[i + l] += d[i]
        d[i - ~r] -= d[i]
print((d[n - 1]))

(n, _), *s = [[*list(map(int, t.split()))] for t in open(0)]
d = [1, -1] + [c := 0] * 2 * n
for i in range(n):
    c = (c + d[i]) % 998244353
    for l, r in s:
        d[i + l] += c
        d[i - ~r] -= c
print(c)

-d = [1, -1] + [0] * 2 * n +d = [1, -1] + [c := 0] * 2 * n -    d[i] = (d[i - 1] + d[i]) % 998244353 +    c = (c + d[i]) % 998244353 -        d[i + l] += d[i] -        d[i - ~r] -= d[i] -print((d[n - 1])) +        d[i + l] += c +        d[i - ~r] -= c +print(c)