#include <bits/stdc++.h>
using namespace std;
int n, m;
int dp[5005][5005];
int a[5005], ptr;
int main() {
  int T;
  cin >> T;
  for (int i = 1; i <= T; i++) {
    int t;
    cin >> t;
    if (t != a[ptr]) a[++ptr] = t;
  }
  for (int k = 1; k < ptr; k++)
    for (int i = 1; k + i <= ptr; i++) {
      int j = k + i;
      if (a[i] == a[j])
        dp[i][j] = dp[i + 1][j - 1] + 1;
      else
        dp[i][j] = min(dp[i + 1][j], dp[i][j - 1]) + 1;
    }
  cout << dp[1][ptr];
}
