#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int dp[5002][5002][2];
const int MAX = std::numeric_limits<int>::max();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j][0] = dp[i][j][1] = (i == j ? 0 : MAX / 2);
    }
  }
  for (int r = 0; r < n; r++) {
    for (int l = r; l >= 0; l--) {
      for (int k = 0; k < 2; k++) {
        int color = (k == 0) ? arr[l] : arr[r];
        if (l)
          dp[l - 1][r][0] =
              min(dp[l - 1][r][0], dp[l][r][k] + (int)(color != arr[l - 1]));
        if ((r + 1) != n)
          dp[l][r + 1][1] =
              min(dp[l][r + 1][1], dp[l][r][k] + (int)(color != arr[r + 1]));
      }
    }
  }
  cout << min(dp[0][n - 1][0], dp[0][n - 1][1]) << endl;
}
