#include <bits/stdc++.h>
using namespace std;
int n, memo[5001][5001];
vector<int> v;
int calc(int l, int r) {
  if (l >= r) return r - l;
  int &ret = memo[l][r];
  if (ret != -1) return ret;
  ret = calc(l + 1, r - 1) + 2;
  ret = min(ret, calc(l + 1, r) + 1);
  ret = min(ret, calc(l, r - 1) + 1);
  if (v[l] == v[r]) ret = min(ret, calc(l + 1, r - 1) + 1);
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  v.erase(unique(v.begin(), v.end()), v.end());
  n = v.size();
  memset(memo, -1, sizeof(memo));
  cout << calc(0, n - 1) << endl;
  return 0;
}
