#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 1000000007 //998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define srt(v)  if(!v.empty())sort(v.begin(),v.end())
#define rev(v)  if(!v.empty())reverse(v.begin(),v.end())
#define PI 3.141592653589793238
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}

ll calc(vector<ll> &a){
    ll sz=a.size();
    ll ans=0;
    
    for(ll i=1;i<sz;i++){
        ll j=i;
        
        while(j<sz&&a[j]==a[i])++j;
        
        i=--j;
        ++ans;
    }
    
    return ans;
}
void solve()
{
  ll n;
  cin>>n;
  
  ll a[n];
  
  for(ll i=0;i<n;i++){
      cin>>a[i];
  }
  
  vector<ll>v1,v2;
  
  vector<ll>v[n+1];
  
  for(ll i=1;i<=n;i++){
      v[i].pb(INF);
  } 
  
  for(ll i=n-1;i>=0;i--){
      v[a[i]].pb(i);
  }
  
 
  
  v1.pb(-1);
  v2.pb(-1);
  
  
  for(ll i=0;i<n;i++){
      v[a[i]].pop_back();
      
      if(v1.back()==a[i]&&v2.back()==a[i]){
           v1.pb(a[i]);        
      }
      else if(v1.back()==a[i]){
          v1.pb(a[i]);
      }
      else if(v2.back()==a[i]){
          v2.pb(a[i]);
      }
      else if(v1.back()==-1)
      {
          v1.pb(a[i]);
      }
      else if(v2.back()==-1){
          v2.pb(a[i]);
      }
      else
      {   
          
          ll x=v[v1.back()].back();
          ll y=v[v2.back()].back();
          
          if(x<y){
              v2.pb(a[i]);
          }
          else
          v1.pb(a[i]);
      }
  }
 
  
  ll ans=calc(v1)+calc(v2);
  
  cout<<ans<<endl;
}
int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
//Start from Here.

  ll t;
  t=1;
// cin>>t;
  while(t--)
  solve();
  
//Good Bye!
    return 0;
}