#include <bits/stdc++.h>
using namespace std;
int arr[5050];
int n;
int dp[5050][5050];
int getLeft(int a) {
  for (int i = a; i >= 1; i--) {
    if (arr[i] != arr[a]) return i + 1;
  }
  return 1;
}
int getRight(int a) {
  for (int i = a; i <= n; i++) {
    if (arr[i] != arr[a]) return i - 1;
  }
  return n;
}
int cal(int a, int b) {
  if (dp[a][b] != -1) return dp[a][b];
  if (a == 1 && b == n) return 0;
  int f1 = 100000;
  int f2 = 100000;
  int aa, bb;
  if (a == 1) {
    bb = getRight(b + 1);
    f2 = 1 + cal(a, bb);
  } else if (b == n) {
    aa = getLeft(a - 1);
    f1 = 1 + cal(aa, b);
  } else {
    aa = getLeft(a - 1);
    bb = getRight(b + 1);
    if (arr[aa] == arr[bb]) {
      f1 = 1 + cal(aa, bb);
    } else {
      f1 = 1 + cal(aa, b);
      f2 = 1 + cal(a, bb);
    }
  }
  return dp[a][b] = min(f1, f2);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  memset(dp, -1, sizeof(dp));
  int ans = 100000;
  for (int i = 1; i <= n; i++) {
    int ix = getRight(i);
    int f1 = cal(i, ix);
    ans = min(ans, f1);
    i = ix;
  }
  printf("%d\n", ans);
  return 0;
}
