Finding minimum element in a list with O(n2)