#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
const int inf = 0x3f3f3f;
int n, x, y, a[maxn], cnt, f[maxn][maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x != y) a[++cnt] = x;
    y = x;
  }
  for (int i = 1; i <= cnt; i++) {
    for (int j = 1; j + i <= cnt; j++) {
      if (a[j] == a[j + i])
        f[j][j + i] = f[j + 1][j + i - 1] + 1;
      else
        f[j][j + i] = min(f[j + 1][j + i], f[j][j + i - 1]) + 1;
    }
  }
  printf("%d", f[1][cnt]);
  return 0;
}
