#include <bits/stdc++.h>
using namespace std;
long long n, x, a[5010], dp[5010][5010];
int main() {
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<int> v;
  v.push_back(a[1]);
  for (int i = 2; i <= n; i++)
    if (a[i] != v[v.size() - 1]) v.push_back(a[i]);
  for (int i = 1; i < v.size(); i++) {
    for (int o = 0; o + i < v.size(); o++) {
      if (v[o] == v[o + i])
        dp[o][o + i] = 1 + dp[o + 1][o + i - 1];
      else
        dp[o][o + i] = 1 + min(dp[o + 1][o + i], dp[o][o + i - 1]);
    }
  }
  cout << dp[0][v.size() - 1] << endl;
}
