1114_D. Flood Fill
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.

Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment from i to j should have the same color.

For example, the line [3, 3, 3] has 1 connected component, while the line [5, 2, 4, 4] has 3 connected components.

The game "flood fill" is played on the given line as follows: 

  * At the start of the game you pick any starting square (this is not counted as a turn). 
  * Then, in each game turn, change the color of the connected component containing the starting square to any other color. 



Find the minimum number of turns needed for the entire line to be changed into a single color.

Input

The first line contains a single integer n (1 ≤ n ≤ 5000) — the number of squares.

The second line contains integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 5000) — the initial colors of the squares.

Output

Print a single integer — the minimum number of the turns needed.

Examples

Input


4
5 2 2 1


Output


2


Input


8
4 5 2 2 1 3 5 5


Output


4


Input


1
4


Output


0

Note

In the first example, a possible way to achieve an optimal answer is to pick square with index 2 as the starting square and then play as follows:

  * [5, 2, 2, 1] 
  * [5, 5, 5, 1] 
  * [1, 1, 1, 1] 



In the second example, a possible way to achieve an optimal answer is to pick square with index 5 as the starting square and then perform recoloring into colors 2, 3, 5, 4 in that order.

In the third example, the line already consists of one color only.
```python
def run_length_compress(string):
    string = string + ["."]
    n = len(string)

    begin = 0
    end = 1
    cnt = 1
    ans = [] 
    while True: 
        if end >= n:
            break
        if string[begin] == string[end]:
            end += 1
            cnt += 1
        else:
            ans.append(string[begin])
            begin = end 
            end = begin + 1
            cnt = 1

    return ans


def lps(string): 
    n = len(string)
    dp = [[0]*n for _ in range(n)] 

    for i in range(n): 
        dp[i][i] = 1
  
    for cl in range(2, n+1): 
        for i in range(n-cl+1): 
            j = i + cl - 1
            
            if string[i] == string[j] and cl == 2: 
                dp[i][j] = 2
            elif string[i] == string[j]: 
                dp[i][j] = dp[i+1][j-1] + 2
            else: 
                dp[i][j] = max(dp[i][j-1], dp[i+1][j])
  
    return dp[0][n-1]

n = int(input())
a = list(map(int, input().split()))

a = run_length_compress(a)
len_pal = lps(a)
print(len(a) - 1 - len_pal//2)
 		  			 					 	  	 							  		
```