#include <bits/stdc++.h>
using namespace std;
const int INF = 5000000;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<int> v;
  v.push_back(0);
  for (int i = 1; i <= n; i++) {
    if (a[i] != a[i - 1]) v.push_back(a[i]);
  }
  n = v.size() - 1;
  vector<vector<int>> dp(n + 1, vector<int>(n + 1, INF));
  for (int i = 1; i <= n; i++) dp[i][i] = 0;
  for (int len = 1; len < n; len++) {
    for (int i = 1; i + len - 1 <= n; i++) {
      if (i >= 1 && i + len <= n && v[i - 1] == v[i + len])
        dp[i - 1][i + len] = min(dp[i - 1][i + len], dp[i][i + len - 1] + 1);
      if (i + len <= n)
        dp[i][i + len] = min(dp[i][i + len], dp[i][i + len - 1] + 1);
      if (i >= 1)
        dp[i - 1][i + len - 1] =
            min(dp[i - 1][i + len - 1], dp[i][i + len - 1] + 1);
    }
  }
  cout << dp[1][n];
  return 0;
}
