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

typedef double db;
typedef long long ll;
typedef unsigned long long ull;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdb = pair<db, db>;
using tiii = tuple<int, int, int>;
using tlll = tuple<ll, ll, ll>;
using tdb = tuple<db, db, db>;
const int maxn = 100010;
const ll mod = 1e9 + 7;
 
int lazy[maxn << 2];
struct Node {
    int l, r, mx;
} t[maxn << 2];
 
inline void pushdown(int x)
{
    lazy[x << 1] += lazy[x], lazy[x << 1 | 1] += lazy[x];
    t[x << 1].mx += lazy[x], t[x << 1 | 1].mx += lazy[x];
    lazy[x] = 0;
}
 
inline void buildtree(int x, int l, int r)
{
    t[x].l = l, t[x].r = r, t[x].mx = 1;
    if (l == r) return;
    int mid = (l + r) >> 1;
    buildtree(x << 1, l, mid);
    buildtree(x << 1 | 1, mid + 1, r);
}
 
inline void change(int x, int l, int r)
{
    if (l > r) return;
    // cerr << x << " " << l << " " << r << endl;
    if (t[x].l == l && t[x].r == r) {
        ++t[x].mx, ++lazy[x];
        return;
    }
    if (lazy[x]) pushdown(x);
    int mid = (t[x].l + t[x].r) >> 1;
    if (r <= mid) change(x << 1, l, r);
    else if (l > mid) change(x << 1 | 1, l, r);
    else change(x << 1, l, mid), change(x << 1 | 1, mid + 1, r);
    t[x].mx = min(t[x << 1].mx, t[x << 1 | 1].mx);
}
 
inline void update(int x, int pos, int k)
{
    if (pos < 0) return;
    // cerr << x << " " << pos << endl;
    if (t[x].l == t[x].r) {
        t[x].mx = min(t[x].mx, k);
        return;
    }
    if (lazy[x]) pushdown(x);
    int mid = (t[x].l + t[x].r) >> 1;
    if (pos <= mid) update(x << 1, pos, k);
    else update(x << 1 | 1, pos, k);
    t[x].mx = min(t[x << 1].mx, t[x << 1 | 1].mx);
}
 
inline int query(int x, int l, int r)
{
    // cerr << x << " " << l << " " << r << endl;
    if (l > r) return 0x3f3f3f3f;
    if (t[x].l == l && t[x].r == r) return t[x].mx;
    if (lazy[x]) pushdown(x);
    int mid = (t[x].l + t[x].r) >> 1;
    if (r <= mid) return query(x << 1, l, r);
    else if (l > mid) return query(x << 1 | 1, l, r);
    else return min(query(x << 1, l, mid), query(x << 1 | 1, mid + 1, r));
}
 
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in", "r", stdin);
        freopen("out", "w", stdout);
    #endif
    int n, pre = -1;
    scanf("%d", &n);
    buildtree(1, 1, n);
    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", &x);
        if (pre == x) {
            int ret = min(query(1, 1, x - 1), query(1, x + 1, n)) + 1;
            ret = min(ret, query(1, x, x));
            update(1, pre, ret);
        } else {
            int ret = min(query(1, 1, x - 1), query(1, x + 1, n)) + 1;
            ret = min(ret, query(1, x, x));
            change(1, 1, n);
            update(1, pre, ret);
        }
        pre = x;
    }
    if (n == 1) puts("1");
    else printf("%d\n", t[1].mx);
    return 0;
}