Problem: The only difference between the two versions is that this version asks the minimal possible answer.
Homer likes arrays a lot. Today he is painting an array with two kinds of colors, white and black. A painting assignment for is described by an array that indicates the color of ( for white and for black).
According to a painting assignment , the array is split into two new arrays and , where is the sub-sequence of all white elements in and is the sub-sequence of all black elements in . For example, if and , then and .
The number of segments in an array , denoted , is the number of elements if we merge all adjacent elements with the same value in . For example, the number of segments in is , because the array will become after merging adjacent elements with the same value. Especially, the number of segments in an empty array is .
Homer wants to find a painting assignment , according to which the number of segments in both and , i.e. , is as small as possible. Find this number.
Input Format: The first line contains an integer ().
The second line contains integers ().
Output Format: Output a single integer, indicating the minimal possible total number of segments.
Note: In the first example, we can choose , and . So the answer is .
In the second example, we can choose , and . So the answer is .