# coding: utf-8
# Your code here!

def main():
    n, k = map(int, input().split())
    s = []
    for _ in range(k):
        l, r = map(int, input().split())
        s.extend(list(range(l, r+1)))
    
    dp = [0] * (2*n+1)
    dp[0] = 1
    
    for i in range(0, n):
        for j in s:
            dp[i+j] += dp[i]
    
    print(dp[n-1] % 998244353)
    
main()
