Finisheh algorithm for the first part