#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int nmax = 5012;
int n, c[nmax], dp[nmax][nmax];
int DP(int l, int r) {
  if (dp[l][r]) return dp[l][r];
  int l2 = l, r2 = r;
  while (l2 < r2 && c[l2] == c[l2 + 1]) ++l2;
  while (l2 < r2 && c[r2] == c[r2 - 1]) --r2;
  if (l2 == r2)
    return dp[l][r] = 0;
  else if (c[l2] == c[r2])
    return dp[l][r] = DP(l2 + 1, r2 - 1) + 1;
  else
    return dp[l][r] = min(DP(l2 + 1, r2), DP(l2, r2 - 1)) + 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
  printf("%d", DP(1, n));
  return 0;
}
