swap m and n if m<n