#include <bits/stdc++.h>
using namespace std;
int dp[5555][5555], n, a[1111111], cnt, b[1111111];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != a[i - 1]) {
      b[++cnt] = a[i];
      dp[cnt][cnt] = 0;
    }
  }
  for (int i = 2; i < cnt; i++) {
    for (int j = 1; j + i <= cnt; j++) {
      int l = j, r = j + i;
      if (b[l] == b[r])
        dp[l][r] = dp[l + 1][r - 1] + 2;
      else {
        dp[l][r] = max(dp[l + 1][r], dp[l][r - 1]);
      }
    }
  }
  if (cnt == 1) {
    cout << 0;
  } else
    cout << (cnt - 1) - dp[1][cnt] / 2;
}
