#include <bits/stdc++.h>
using namespace std;
long long int u = 1000000000;
int flag = 0;
int a[5001];
int dp[5001][5001][2];
int main() {
  long long int n, i, j, x, y;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      dp[i][j][0] = 5000;
      dp[i][j][1] = 5000;
    }
  }
  for (i = 0; i < n; i++) {
    dp[i][0][0] = 0;
    dp[i][0][1] = 0;
  }
  for (i = 1; i < n; i++) {
    for (j = 0; j < n - i; j++) {
      x = dp[j + 1][i - 1][0];
      if (a[j + 1] != a[j]) x = x + 1;
      y = dp[j + 1][i - 1][1];
      if (a[j + i] != a[j]) y = y + 1;
      dp[j][i][0] = min(x, y);
      x = dp[j][i - 1][0];
      if (a[j] != a[j + i]) x = x + 1;
      y = dp[j][i - 1][1];
      if (a[j + i - 1] != a[j + i]) y = y + 1;
      dp[j][i][1] = min(x, y);
      if (a[j] == a[j + i]) {
        x = min(dp[j][i][1], dp[j][i][0]);
        dp[j][i][0] = x;
        dp[j][i][1] = x;
      }
    }
  }
  x = 0;
  x = min(dp[0][n - 1][1], dp[0][n - 1][0]);
  cout << x;
  return 0;
}
