Implemented sorted brute force.