Son Halo owns
Every two spaceships with consequent numbers are connected by a rope, and the first one is connected to the station. The rope number
Son Halo considers that the rope
Son Halo wants to rearrange spaceships in such a way, that there are no rope intersections. Because he is lazy, he wants to rearrange the ships in such a way, that the total number of ships that remain at their original position
Your task is to figure out what is the maximal number of ships that can remain at their initial positions.
Input Specification
The first line of the input file contains
Output Specification
The output file must contain one integer — the maximal number of ships that can remain at their initial positions in the solution of this problem.
Sample Input 1
4
1 3 2 4
Sample Output 1
3
Sample Input 2
4
1 4 2 3
Sample Output 2
4
Note
In the first sample, Son Halo can move the second spaceship in the position between the first and the third to solve the problem while keeping 3 other ships at their initial positions.
In the second sample, there are no rope intersections, so all 4 ships can be left at their initial positions.
Comments