#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,i,j,k;
    cin>>n;
    vector<int> a;
    vector<int> left(n+1,-1);
    for(i=0;i<n;i++){
        cin>>m;
        if(a.size() && m==a.back()) continue;
        a.push_back(m);
    }
    n=a.size();
    vector<int> next(n+1);
    for(i=n-1;i>=0;i--){
        if(left[a[i]]==-1) next[i]=n;
        else{
            next[i]=left[a[i]];
        }
        left[a[i]]=i;
    }

    int dp[n+1];
    dp[n]=0;
    for(i=n-1;i>=0;i--){
        if(next[i]==n){
            dp[i]=1+dp[i+1];
        }
        else{
            dp[i]=min(1+dp[i+1],next[i]-i-2+dp[next[i]-1]);
        }
    }
    cout<<dp[0]<<endl;
}
