#include <bits/stdc++.h>
using namespace std;
using ll = int;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
struct d_ {
  template <typename T>
  d_ &operator,(const T &x) {
    cerr << ' ' << x;
    return *this;
  }
  template <typename T>
  d_ &operator,(const vector<T> &x) {
    for (auto x : x) cerr << ' ' << x;
    return *this;
  }
} d_t;
const ll MX = 5007;
ll DP[MX][MX][2];
ll n;
ll c[MX];
ll dp(ll i, ll j, bool r) {
  ll &ret = DP[i][j][r];
  if (~ret) return ret;
  if (i == j) return ret = 0;
  ll ref = (r ? j : i);
  ret = min((c[i + 1] != c[i]) + (c[i] != c[ref]) + dp(i + 1, j, 0),
            min((c[i] != c[j]) + (c[j] != c[ref]) + dp(i, j - 1, 0),
                min((c[j - 1] != c[j]) + (c[j] != c[ref]) + dp(i, j - 1, 1),
                    (c[j] != c[i]) + (c[i] != c[ref]) + dp(i + 1, j, 1))));
  return ret;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (ll i(0); i < n; i++) cin >> c[i];
  (memset(DP, -1, sizeof(DP)));
  cout << min(dp(0, n - 1, 0), dp(0, n - 1, 1)) << endl;
  return 0;
}
