we n chip position ith chip positioniWe need chip position in step change position ith chip positioni topositioni 2 positioni 2 cost 0positioni 1 positioni 1 cost 1return minimum cost need chip position Example 1input position 123output 1explanation first step move chip position 3 position 1 cost 0second step move chip position 2 position 1 cost 1total cost 1example 2input position 22233output 2explanation we chip position 3 position 2 each cost 1 the total cost 2example 3input position 11000000000output 1 Constraints1 positionlength 1001 positioni 109