minimize n-m, to sort a array