#include <bits/stdc++.h>
using namespace std;
int dp[5010][5010];
int a[100000];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> d;
  d.push_back(0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i == 1 || a[i] != a[i - 1]) d.push_back(a[i]);
  }
  for (int i = 1; i <= 5001; i++)
    for (int j = 1; j <= 5001; j++) {
      dp[i][j] = 1e9;
    }
  n = d.size() - 1;
  for (int i = n; i >= 1; i--) {
    dp[i][i] = 0;
    for (int j = i; j <= n; j++) {
      if (d[i - 1] == d[j + 1])
        dp[i - 1][j + 1] = min(dp[i - 1][j + 1], dp[i][j] + 1);
      dp[i - 1][j] = min(dp[i][j] + 1, dp[i - 1][j]);
      dp[i][j + 1] = min(dp[i][j] + 1, dp[i][j + 1]);
    }
  }
  cout << dp[1][n];
}
