#include <bits/stdc++.h>
using namespace std;
int n, dp[5050][5050], b[5050];
vector<int> v;
int go(int l, int r) {
  if (dp[l][r]) return dp[l][r];
  if (l == r) {
    return 0;
  }
  if (l == r - 1) {
    return v[l] != v[r];
  }
  if (v[l] == v[r]) {
    return dp[l][r] = go(l + 1, r - 1) + 1;
  } else {
    return dp[l][r] = min(go(l + 1, r) + 1, go(l, r - 1) + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    if (i > 0 and v[v.size() - 1] == t) continue;
    v.push_back(t);
  }
  n = v.size();
  cout << go(0, n - 1);
}
