Naive algorithm