#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
#define ve vector 
#define maxe(v) *max_element(v.begin(),v.end())
#define maxes(a,n) *max_element(a,a+n)
#define mine(v) *min_element(v.begin(),v.end())
#define mines(a,n) *min_element(a,a+n)
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007
#define all(v) v.begin(),v.end()
#define PRECISE cout.precision(18);
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fs first
#define se second

int main()
{
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
	FAST
	ll n;cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
		cin>>a[i];
	ve<ve<ll>> v(n+1);
	for(ll i=n-1;i>=0;i--)
	{
		v[a[i]].pb(i);
	}
	ve<ll> a0;ve<ll> a1;
	a0.pb(0);a1.pb(0);
	for(ll i=0;i<n;i++)
	{
		ll x=a0.back();
		ll y=a1.back();
		ll z=a[i];
		v[z].pop_back();
		if(x==z)
		{
			a0.pb(z);
		}
		else if(y==z)
		{
			a1.pb(z);
		}
		else
		{
			if(!v[x].empty()&&!v[y].empty())
			{
				ll x1=v[x].back();
				ll y1=v[y].back();
				if(x1>y1)
					a0.pb(z);
				else
					a1.pb(z);
			}
			else if(v[x].empty()&&!v[y].empty())
			{
					
					a0.pb(z);
					
			}
			else if(!v[x].empty()&&v[y].empty())
			{
					
					a1.pb(z);
					
			}
			else
			{
					a1.pb(z);
			}
		}

	}
	ll i=0;n=a0.size();ll ans=0;
	while(i<n)
	{
		ans++;
		while(a0[i]==a0[i+1]&&i<n-1)
		{
			i++;
		}
		i++;
	}
	n=a1.size();i=0;

	while(i<n)
	{
		ans++;
		while(a1[i]==a1[i+1]&&i<n-1)
		{
			i++;
		}
		i++;
	}
	cout<<ans-2;


}