def solve():
    N, K = map(int,input().split())
    L = []
    R = []
    S = set()
    MOD = 998244353
    for _ in range(K):
        l, r = map(int,input().split())
        L.append(l)
        R.append(r)

        for i in range(l, r+1):
            S.add(i)

    dp = [0] * (N+1)
    dp[1] = 1

    for i in range(1,N+1):
        for s in S:
            if i+s >= N+1:
                break
            dp[i+s] += dp[i] % MOD
            dp[i+s] %= MOD
    
    print(dp[-1])
    
if __name__ == '__main__':
    solve()