#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 5005;
int n;
int a[N], b[N], c[N];
int f[N][N];
int dp(int i, int j) {
  if (f[i][j] != -1) return f[i][j];
  if (i == j) return f[i][j] = 0;
  if (c[i] == c[j]) {
    if (j == i + 1)
      return f[i][j] = 0;
    else
      return dp(i + 1, j - 1) + 1;
  }
  return f[i][j] = min(dp(i + 1, j) + 1, dp(i, j - 1) + 1);
}
int main() {
  cin >> n;
  memset(f, -1, sizeof(f));
  for (int i = 1; i <= n; i++) cin >> a[i];
  int cnt = 0, t = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] != a[i - 1]) {
      if (!b[a[i]]) b[a[i]] = ++t;
      c[++cnt] = b[a[i]];
    }
  cout << dp(1, cnt);
  return 0;
}
