def main():
    N, K = map(int,input().split())
    moves = []
     
    mod = 998244353
     
    for _ in range(K):
        L, R = map(int,input().split())
        # for d in range(L, R+1):
        #     moves.append(d)
        moves.append((L, R))
    # moves.sort()
     
    dp = [0] * (N + 1)
    dp[1] = 1
    # for dis in moves:
    #     dp[dis] = 1
    # print(moves)
     
    for n in range(1, N+1):
        for L, R in moves:
            if n - L <= 0 :
                continue
            for dis in range(L, R+1):
                if n - dis >= 1:
                    dp[n] += dp[n - dis] % mod
                else:
                    break
     
    # print(dp)
    print(dp[N] % mod)

if __name__ == "__main__":
    main()
