There are vertical poles, one at each vertex of a regular -gon. Viewed from above, the poles are numbered in clockwise order.
You may add horizontal rungs at arbitrary heights, each joining two adjacent poles. Poles and are also adjacent. Multiple rungs may join the same pair of poles, and distinct rungs may be placed at the same height. However, two rungs at the same height must not share an endpoint pole.
Starting at the top of a pole, move downward. Whenever you encounter a rung, follow it to the other pole and continue downward. Repeat until you reach the bottom.
You are given a permutation . Arrange the rungs so that starting at the top of pole leads to the bottom of pole .
Find the minimum possible number of rungs.
The input is given in the following format:
Print the minimum possible number of rungs on a single line.
is a permutation of the integers from to .