#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
int dp[5010][5010];
void solve() {
  int n;
  cin >> n;
  memset(dp, -1, sizeof dp);
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  v.resize(unique(v.begin(), v.end()) - v.begin());
  for (int j = 0; j < v.size(); j++) {
    for (int i = j; i >= 0; i--) {
      dp[i][j] = INT_MAX;
      if (i == j) {
        dp[i][j] = 0;
        continue;
      }
      if (i == j - 1) {
        dp[i][j] = 1;
        continue;
      }
      if (v[i] == v[j]) {
        dp[i][j] = 1 + dp[i + 1][j - 1];
      } else {
        dp[i][j] = min(dp[i][j], min(dp[i + 1][j] + 1, dp[i][j - 1] + 1));
      }
    }
  }
  cout << dp[0][v.size() - 1];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
