def resolve():
    #n=int(input())
    #a,b=map(int,input().split())
    #x=list(map(int,input().split()))
    #a=[list(map(lambda x:int(x)%2,input().split())) for _ in range(h)]
    import numpy as np
    n,k=map(int,input().split())
    a=[0]*n
    a=np.array(a)
    MOD=998244353
    for i in range(k):
      l,r=map(int,input().split())
      a[l-1:r]=1
    dp=[0]*n*2
    dp[0]=1
    dp=np.array(dp)
    for i in range(1,n):
      if dp[i-1]==0:
        continue
      else:
        dp[i:i+n]+=dp[i-1]*a
        dp[i:i+n]%=MOD
    print(dp[n-1])
    
if __name__ == '__main__':
    resolve()