#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 19;
int c1[N], c2[N], c[N];
int f[N][N];
int n;
int main() {
  scanf("%d", &n);
  int pre = -1;
  int now = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    if (x == pre) continue;
    if (x != pre) {
      c[++now] = x;
      pre = x;
    }
  }
  n = now;
  for (int i = 1; i <= n; ++i) {
    c1[i] = c[i];
    c2[n - i + 1] = c[i];
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      if (c1[i] == c2[j])
        f[i][j] = f[i - 1][j - 1] + 1;
      else
        f[i][j] = max(f[i - 1][j], f[i][j - 1]);
    }
  int ans = 1e9 + 7;
  for (int i = 1; i <= n; ++i) ans = min(ans, n - f[i - 1][n - i]);
  cout << ans - 1 << endl;
  return 0;
}
