from bisect import*
n,k=map(int,input().split());D=[];S=[1]+[0]*~-n;m=998244353
for _ in "_"*k:D+=eval("[*range("+input().replace(" ",",")+"+1)]")
D.sort()
for i in range(2,n+1):
  for d in D[:bisect(D,i)]:S[i-1]+=S[i-d-1]
  S[i-1]%=m
print(S[-1])