optimization: search for minimum element in the list instead of sorting it and taking its head