#include <bits/stdc++.h>
using namespace std;
long long modpow(long long b, long long e, long long mod) {
  long long ans = 1;
  for (; e; b = b * b % mod, e /= 2)
    if (e & 1) ans = ans * b % mod;
  return ans;
}
const int N = 5050;
int dp[N][N][2], c[N], n;
bool vis[N][N][2];
int solve(int x, int y, int z) {
  if (x < 0 || y > n || x > y) return (int)1e9;
  if (x == 1 && y == n) return 0;
  if (vis[x][y][z]) return dp[x][y][z];
  vis[x][y][z] = true;
  return dp[x][y][z] =
             min(solve(x - 1, y, 0) + (c[z ? y : x] == c[x - 1] ? 0 : 1),
                 solve(x, y + 1, 1) + (c[z ? y : x] == c[y + 1] ? 0 : 1));
}
int32_t main() {
  cin >> n;
  for (int i = 0; i < (n); ++i) cin >> c[i + 1];
  int ans = (int)1e9;
  for (int i = 0; i < (n); ++i) ans = min(ans, solve(i + 1, i + 1, 0));
  cout << ans << endl;
}
