#include <bits/stdc++.h>
using namespace std;
const int N = 5005, inf = 1000000000;
int n, a[N];
int dp1[N][N][2];
void initdp1() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp1[i][j][0] = dp1[i][j][1] = (i == j ? 0 : inf);
    }
  }
}
void upddp1(int &a, int b) { a = min(a, b); }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  initdp1();
  for (int j = 1; j <= n; j++) {
    for (int i = j; i >= 1; i--) {
      for (int bit = 0; bit <= 1; bit++) {
        int col = bit ? a[j] : a[i];
        if (i > 1) upddp1(dp1[i - 1][j][0], dp1[i][j][bit] + (col != a[i - 1]));
        if (j < n) upddp1(dp1[i][j + 1][1], dp1[i][j][bit] + (col != a[j + 1]));
      }
    }
  }
  printf("%d\n", min(dp1[1][n][0], dp1[1][n][1]));
}
