import numpy as np

n , k = map(int, input().split())

li = np.array([0]*(n+2))
lis2 =np.array([0]*(3*n))
lis2[1]=1

for i in range(k):
    l,r = map(int, input().split())
    li[l]=1
    li[r+1]=-1

for i in range(1,n+1):
    li[i]+=li[i-1]

for i in range(1,n):
    lis2[i]%=998244353
    lis2[i:i+n+2]+=li*lis2[i]

print(lis2[n]%998244353)
