#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long exp(long long x, long long y) {
  x %= 1000000007;
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % 1000000007;
    x = x * x % 1000000007;
    y >>= 1;
  }
  return res;
}
long long fact(long long n) {
  long long res = 1;
  for (long long i = 2; i <= n; i = i + 1) (res *= i) %= 1000000007;
  return res;
}
bool isprime(long long n) {
  if (n <= 1) return 0;
  for (long long i = 2; i * i <= n; ++i)
    if (n % i == 0) return 0;
  return 1;
}
const int N = 5005;
int dp[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  for (int i = n - 1; i >= 0; --i) {
    for (int j = i + 1; j < n; ++j) {
      dp[i][j] = min({dp[i + 1][j] + (v[i] != v[i + 1]),
                      dp[i][j - 1] + (v[j] != v[j - 1]),
                      dp[i + 1][j - 1] + 1 + (v[i] != v[j])});
    }
  }
  cout << dp[0][n - 1];
  return 0;
}
