#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
//#define endl "\n"
const ll maxn =6e5+10;
const ll mod=1e9+7;
const ll base=1e18;
ll a[maxn];
vector<ll> adj[maxn];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("t.inp","r"))
    {
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
    ll n;
    cin>>n ;
    ll pre1=0;
    ll pre2=0;
    ll ans=0;
    ll last=-1;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    vector<ll> vt;
    for (int i=1; i<=n; i++)
    {
        ll j=i;
        while (j<=n&&a[j]==a[i])
            j++;
        j--;
        ll cnt=j-i+1;
       vt.pb(a[i]);
       adj[a[i]].pb(vt.size());
        i=j;
    }
    ll j=0;
    if (vt.size()<=2)
    {
        cout <<vt.size();
        return 0;
    }
    /*pre1=vt[0];
    pre2=vt[1];
    ans=2;*/
    for (ll i=0; i<vt.size(); i++)
    {
     //   cout <<vt[i]<<endl;
        ll x=vt[i];
      /* if (i==vt.size()-1)
       {
             if (pre1==x||pre2==x)
             {

             }
             else
             {
                 ans++;
             }
       }
       else
       {*/
            if (pre1==x||pre2==x)
            {

            }
            else
            {
                ans++;
                ll x1=vt[i+1];
                auto h=upper_bound(adj[pre1].begin(),adj[pre1].end(),i)-adj[pre1].begin();
                auto h1=upper_bound(adj[pre2].begin(),adj[pre2].end(),i)-adj[pre2].begin();
                if (h==adj[pre1].size()&&h1==adj[pre2].size())
                {
                     pre1=x;
                }
                else
                {
                    if (h==adj[pre1].size())
                    {
                       pre1=x;
                    }
                    else if (h1==adj[pre2].size())
                    {
                        pre2=x;
                    }
                    else if (adj[pre1][h]>adj[pre2][h1])
                    {
                        pre1=x;
                    }
                    else
                    {
                        pre2=x;
                    }
                }
            }

     //  cout <<ans<<" "<<pre1<<" "<<pre2<<endl;
    }
    cout <<ans;






}
