#include <bits/stdc++.h>
using namespace std;
int a[5009], dp[5009][5009][2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int i = 0, j, l;
  while (i < n) cin >> a[i++];
  i = 1;
  while (i < n) {
    l = 0;
    j = l + i;
    while (j < n) {
      dp[l][j][0] = min(dp[l + 1][j][0] + 1 - (int)(a[l] == a[l + 1]),
                        dp[l + 1][j][1] + 1 - (int)(a[l] == a[j]));
      dp[l][j][1] = min(dp[l][j - 1][1] + 1 - (int)(a[j] == a[j - 1]),
                        dp[l][j - 1][0] + 1 - (int)(a[l] == a[j]));
      j++;
      l++;
    }
    i++;
  }
  cout << min(dp[0][n - 1][0], dp[0][n - 1][1]) << "\n";
}
