#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MAXN = 5005;
int n, cnt;
int a[MAXN];
int dp[MAXN][MAXN];
int main() {
  scanf("%d", &n);
  a[0] = -inf;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] != a[cnt]) a[++cnt] = a[i];
  }
  n = cnt;
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 1; i <= n; ++i) dp[i][i] = 0;
  for (int len = 2; len <= n; ++len)
    for (int l = 1, r = l + len - 1; r <= n; ++l, ++r) {
      if (a[l] == a[r]) dp[l][r] = min(dp[l][r], dp[l + 1][r - 1] + 1);
      dp[l][r] = min(dp[l][r], dp[l + 1][r] + 1);
      dp[l][r] = min(dp[l][r], dp[l][r - 1] + 1);
    }
  printf("%d\n", dp[1][n]);
  return 0;
}
