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)]
    n,k=map(int,input().split())
    a=set()
    MOD=998244353
    for i in range(k):
      l,r=map(int,input().split())
      for j in range(l-1,r):
        a.add(j)
    dp=[0]*n*2
    dp[0]=1
    for i in range(1,n):
      x=dp[i-1]
      if x==0:
        continue
      else:
        for j in a:
          dp[i+j]+=x
          dp[i+j]%=MOD
    print(dp[n-1])
    
if __name__ == '__main__':
    resolve()