#include <bits/stdc++.h>
using namespace std;
const long long sz = 5005;
long long n;
vector<long long> v;
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    if (i == 0 || x != v.back()) v.push_back(x);
  }
  n = v.size();
  long long dp[n][n];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j + i < n; j++) {
      if (i == 0)
        dp[j][i + j] = 0;
      else {
        dp[j][i + j] = min(dp[j][i + j - 1] + 1, dp[j + 1][i + j] + 1);
        if (v[j] == v[i + j])
          dp[j][i + j] = min(dp[j][i + j], dp[j + 1][i + j - 1] + 1);
      }
    }
  }
  cout << dp[0][n - 1];
}
