#include <bits/stdc++.h>
using namespace std;
int n;
int dp[5005][5005];
vector<int> a;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (!a.size() or x != a.back()) a.push_back(x);
  }
  n = a.size();
  for (int i = 0; i < n; i++) dp[i][i] = 1;
  for (int k = 2; k <= n; k++) {
    for (int i = 0; i < n - k + 1; i++) {
      int j = i + k - 1;
      if (a[i] == a[j] and k == 2)
        dp[i][j] = 2;
      else if (a[i] == a[j])
        dp[i][j] = dp[i + 1][j - 1] + 2;
      else
        dp[i][j] = max(dp[i][j - 1], dp[i + 1][j]);
    }
  }
  cout << n - (dp[0][n - 1] + 1) / 2 << endl;
  return 0;
}
