#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
int n, a[N], dp[N][N], u[N][N];
vector<int> v;
int get(int l, int r) {
  if (l >= r) return 0;
  if (u[l][r]) return dp[l][r];
  dp[l][r] = 1e9;
  u[l][r] = 1;
  get(l, r - 1);
  get(l + 1, r);
  if (v[l] == v[r]) {
    dp[l][r] = get(l + 1, r - 1) + 1;
  } else {
    dp[l][r] = min(get(l + 1, r) + 1, get(l, r - 1) + 1);
  }
  return dp[l][r];
}
int main() {
  cin >> n;
  v.push_back(0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i - 1] != a[i]) v.push_back(a[i]);
  }
  n = v.size() - 1;
  cout << get(1, n) << endl;
}
