#include <bits/stdc++.h>

using namespace std;

#ifdef Adrian
#include "debug.h"
#else
#define debug(...) 9999
#endif

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef complex<int> point;
#define F first
#define S second
#define ii pair<int,int>



int main() {
#ifdef Adrian
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0); cin.tie(0);
#endif


    int m;
    cin>>m;
    vector<int> v;
    for(int i=0, x; i<m; i++)
    {
        cin>>x;
        if(v.empty() || v.back() != x)
            v.push_back(x);
    }
    int n = v.size();

    vector<int> r(n), l(m, n);
    for(int i=n-1; i>=0; i--)
        r[i] = l[v[i]], l[v[i]] = i;

    const int oo = 1e9;
    vector<int> dp(n, oo);
    dp[0] = 1;

    for(int i=1; i<n-1; i++)
    {
        dp[i] = min(dp[i], i + 1);
        int x = r[i - 1], y = r[i];

        dp[i + 1] = min(dp[i  + 1], dp[i] + 1);
        if(x > i && x < n) dp[x] = min(dp[x], dp[i] + x - i - 1);
        if(y < n) dp[y] = min(dp[y], dp[i] + y - i - 1);
    }

    cout<<dp[n - 1]<<'\n';







    return 0;
}


