#include <bits/stdc++.h>
using namespace std;
long long *arr, n;
long long** dp;
long long func(long long i, long long j) {
  long long t = arr[i], u = arr[j], x = i, y = j;
  if (arr[i] == arr[j]) {
    while (i <= n && arr[i] == t) i++;
    while (j > 0 && arr[j] == u) j--;
    if (i > j) return 0;
    return dp[x][y] = func(i, j) + 1;
  }
  if (dp[x][y] != -1) return dp[x][y];
  while (i <= n && arr[i] == t) {
    i++;
  }
  while (j > 0 && arr[j] == u) j--;
  return dp[x][y] = min(func(i, y), func(x, j)) + 1;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  arr = new long long[n + 1];
  dp = new long long*[n + 1];
  dp[0] = new long long[n + 1];
  for (long long i = 1; i < n + 1; ++i) {
    cin >> arr[i];
    dp[i] = new long long[n + 1];
  }
  for (long long i = 0; i < n + 1; ++i) {
    for (long long j = 0; j < n + 1; ++j) dp[i][j] = -1;
  }
  cout << func(1, n);
}
