#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
int n, a[N], b[N], dp[N][N];
int solve(int l, int r) {
  int k;
  if (l == r) return 0;
  if (dp[l][r]) return dp[l][r];
  if (b[l] == b[r]) {
    if (l == r + 1) {
      dp[l][r] = 0;
      return 0;
    } else {
      k = solve(l + 1, r - 1) + 1;
    }
  } else {
    k = min(solve(l + 1, r), solve(l, r - 1)) + 1;
  }
  dp[l][r] = k;
  return k;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int m = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] != a[i - 1]) {
      b[++m] = a[i];
    }
  }
  printf("%d\n", solve(1, m));
  return 0;
}
