def f():    
    n, k = map(int,input().split())
    mod = 998244353
    m = []
    for i in range(k):
        l, r = map(int,input().split())
        for j in range(l, r+1):
            m.append(j)
    
    m.sort()
    m = set(m)
    
    
    dp = [0]*(n)
    dp[0] = 1
    for i in range(n-1):
        for j in m:
            if i+1 >= j:
                dp[i+1] += dp[i+1-j]%mod
                
    
    print(dp[-1]%mod)

if __name__ == '__main__':
    f()