Bubbles can affect this dynamic temporarily, but eventually they always pop, usually leading to a temporary condition of too little investment in N. Believe me, it was not "cool" to be a dot com founder in 2001.
But in the long run, this cycle averages out such that free markets don't have long term misallocations of resources.
Whether the system we currently have can be described as a free market, though, is a question for another day.