def main():
    import sys
    input = sys.stdin.buffer.readline
    
    n,k = map(int,input().split())
    tmpset = set()
    for _ in range(k):
        morty,morty1= map(int,input().split())
        for i in range(morty,morty1+1):
            tmpset.add(i)
        
    dp = [0]*(n+1)
    dp[0] = 1
    for i in range(len(dp)):
        if(dp[i]>0):
            for tmp in tmpset:
                if tmp+i<=n:
                    dp[tmp+i]+=dp[i]
                    dp[tmp+i]%=998244353
    print(dp[n-1])


        


    




















if __name__ == "__main__":
    main()