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

#define pb push_back
#define F first
#define S second
#define ld long double
#define ll long long
#define ull unsigned ll
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define endl '\n'

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N = 3e5 + 10;
const int M = 5e5 + 10;
const ll MOD = 1e9 + 7;
const ll p1 = 57, M1 = 1e9 + 3;
const int rx[4] = {-1, 0, 1, 0};
const int ry[4] = {0, 1, 0, -1};
const int hx[8] =  {-2, -2, -1, 1, 2, 2, 1, -1};
const int hy[8] = {-1, 1, 2, 2, 1, -1, -2, -2};
const ld eps = 1e-7;
const ld pi = acos(-1.0);
const ll INF = 1e9 + 1000;

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("game.in", "r", stdin);
//    freopen("game.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    vector <int> pos[n + 1];
    for (int i = n - 1; i >= 0; i--) {
        pos[a[i]].pb(i);
    }
    vector <int> f(n + 1, INF);
    for (int i = 1; i <= n; i++) {
        if (pos[i].size() != 0) f[i] = pos[i].back();
    }
    vector <int> v1, v2;
    for (int i = 0; i < n; i++) {
        pos[a[i]].pop_back();
        if (pos[a[i]].size() > 0) {
            f[a[i]] = pos[a[i]].back();
        } else f[a[i]] = INF;
        if (i == 0) v1.pb(a[i]);
        else if (v1.size() == 0) {
            if (v2.back() == a[i]) v2.pb(a[i]);
            else {
                v1.pb(a[i]);
            }
        } else if (v2.size() == 0) {
            if (v1.back() == a[i]) v1.pb(a[i]);
            else {
                v2.pb(a[i]);
            }
        } else {
            int x = v1.back(), y = v2.back();
            if (x == a[i] && y == a[i]) v1.pb(a[i]);
            else if (x == a[i]) v1.pb(a[i]);
            else if (y == a[i]) v2.pb(a[i]);
            else {
                if (f[x] < f[y]) v2.pb(a[i]);
                else v1.pb(a[i]);
            }
        }
    }
//    for (auto it : v1) {
//        cout << it << " ";
//    }
//    cout << endl;
//    for (auto it : v2) {
//        cout << it << " ";
//    }
//    cout << endl;
    int res = (v1.size() > 0) + (v2.size() > 0);
    for (int i = 1; i < v1.size(); i++) {
        if (v1[i] != v1[i - 1]) res ++;
    }
    for (int i = 1; i < v2.size(); i++) {
        if (v2[i] != v2[i - 1]) res ++;
    }
    cout << res << endl;
    return 0;
}
