#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int dp[N][N];
int a[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  a[n + 1] = -1;
  vector<int> x;
  for (int i = 1; i <= n; ++i) {
    if (a[i] != a[i - 1]) x.push_back(a[i - 1]);
  }
  n = (int)x.size();
  for (int i = 0; i + 1 < n; ++i) {
    dp[i][i + 1] = 1;
  }
  for (int len = 3; len <= n; ++len) {
    for (int l = 0; l + len - 1 < n; ++l) {
      int r = l + len - 1;
      dp[l][r] = min(dp[l + 1][r], dp[l][r - 1]) + 1;
      if (x[l] == x[r]) {
        dp[l][r] = min(dp[l][r], dp[l + 1][r - 1] + 1);
      }
    }
  }
  cout << dp[0][n - 1];
  return 0;
}
