#include <bits/stdc++.h>
using namespace std;
 
//#define int long long
#define all(x) (x).begin(),(x).end()
#define pb push_back

signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n; cin >> n;
  int on = n;
  int a[n];
  vector<array<int, 2>> segs;
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<int> b;
  for(int i = 0; i < n;) {
    int st = i;
    while(i < n && a[i] == a[st]) {
      ++i;
    }
    b.pb(a[st]);
  }
  n = b.size();
  vector<int> inds[on + 1];
  for(int i = 0; i < n; ++i) {
    inds[b[i]].pb(i);
  }
  for(int i = 0; i <= on; ++i) {
    if(inds[i].size()) {
      reverse(all(inds[i]));
    }
  }
  array<int, 3> dp[n + 1];
  for(int i = 0; i <= n; ++i) {
    dp[i] = {-1, -1, (int)1e9};
  }
  dp[0] = {-1, -1, 0};
  for(int i = 0; i < n; ++i) {
    inds[b[i]].pop_back();
    if(dp[i][0] == b[i]) {
      dp[i + 1] = {b[i], dp[i][1], dp[i][2]};
    } else if(dp[i][1] == b[i]) {
      dp[i + 1] = {dp[i][0], b[i], dp[i][2]};
    } else {
      int i1 = 1e9, i2 = 1e9;
      if(dp[i][0] != -1 && inds[dp[i][0]].size()) {
        i1 = inds[dp[i][0]].back();
      }
      if(dp[i][1] != -1 && inds[dp[i][1]].size()) {
        i2 = inds[dp[i][1]].back();
      }
      if(i1 < i2) {
        dp[i + 1] = {dp[i][0], b[i], dp[i][2] + 1};
      } else {
        dp[i + 1] = {b[i], dp[i][1], dp[i][2] + 1};
      }
    }
  }
  cout << dp[n][2] << "\n";
}