#include <bits/stdc++.h>
using namespace std;
mt19937 gen(time(NULL));
template <typename T = int>
inline T read() {
  T number = 0, numberSign = 1;
  char currentChar = getchar();
  while (currentChar < '0' or currentChar > '9') {
    if (currentChar == '-') numberSign = -1;
    currentChar = getchar();
  }
  while (currentChar >= '0' and currentChar <= '9') {
    number = (number << 3) + (number << 1) + (currentChar - '0');
    currentChar = getchar();
  }
  return number * numberSign;
}
int dp[5005][5005];
int a[5005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  for (int i = 0; i < 5005; ++i) dp[i][i] = 0;
  for (int i = n; i >= 1; --i) {
    for (int j = i; j <= n; ++j) {
      if (a[i - 1] == a[i])
        dp[i - 1][j] = min(dp[i][j], dp[i - 1][j]);
      else
        dp[i - 1][j] = min(dp[i][j] + 1, dp[i - 1][j]);
      if (a[j + 1] == a[j])
        dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
      else
        dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
      if (a[i - 1] == a[j + 1])
        dp[i - 1][j + 1] = min(dp[i - 1][j + 1], dp[i][j] + 1);
    }
  }
  cout << dp[1][n] << '\n';
  return 0;
}
