New function to search for maxmin