#include <bits/stdc++.h>
using namespace std;
int c[5005], dp[5005][5005][2];
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j)
        dp[i][j][0] = dp[i][j][1] = 0;
      else
        dp[i][j][0] = dp[i][j][1] = 0x3f3f3f3f;
    }
  }
  for (int len = 2; len <= n; len++) {
    for (int i = 1; i <= n; i++) {
      int j = len - 1 + i;
      if (j > n) break;
      dp[i][j][0] = min(dp[i][j][0], dp[i + 1][j][0] + (c[i] != c[i + 1]));
      dp[i][j][0] = min(dp[i][j][0], dp[i + 1][j][1] + (c[j] != c[i]));
      dp[i][j][1] = min(dp[i][j][1], dp[i][j - 1][0] + (c[i] != c[j]));
      dp[i][j][1] = min(dp[i][j][1], dp[i][j - 1][1] + (c[j - 1] != c[j]));
    }
  }
  cout << min(dp[1][n][0], dp[1][n][1]) << endl;
  return 0;
}
