#include <bits/stdc++.h>
using namespace std;
int a[10100];
int dp[5555][5555][2];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 0; k < 2; ++k) {
        if (j != i) {
          dp[i][j][k] = 0x3f3f3f3f;
        }
      }
    }
  }
  for (int len = 2; len <= n; ++len) {
    for (int j = 1; j + len - 1 <= n; ++j) {
      int L = j;
      int R = len + j - 1;
      dp[L][R][0] = min(dp[L + 1][R][0] + (a[L] != a[L + 1]),
                        dp[L + 1][R][1] + (a[L] != a[R]));
      dp[L][R][1] = min(dp[L][R - 1][0] + (a[L] != a[R]),
                        dp[L][R - 1][1] + (a[R - 1] != a[R]));
    }
  }
  cout << min(dp[1][n][0], dp[1][n][1]) << endl;
  return 0;
}
