#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int n;
int a[200000];
int f[200000];
int c[200000];
int r[200000];

struct point
{
  int x;
  int open;
  point(){}
  point(int _x, int b)
  {
      x=_x;
      open=b;
  }
  bool operator<(const point &other)
  const{
      if(x<other.x) return true;
      if(x==other.x) return open>other.open;
      return false;
  }
};

point p[300000];

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        if(f[a[i]]==0){ c[a[i]]++; f[a[i]]=i; r[a[i]]=i;}
        else { r[a[i]]=i; c[a[i]]++; }
    }

    int m=0;
    for(int i=0; i<=n; i++)
    {
        if(f[i]!=0)
        {
            p[m]=point(f[i],1); m++;
            p[m]=point(r[i],0); m++;
            //cout << i << ' ' << f[i] << ' ' << r[i] << endl;
            //if(r[i]-f[i]+1!=c[i]) res++;
        }
    }

    sort(p,p+m);

    int cnt=0, mx=0, res=0;
    for(int i=0; i<m; i++)
    {
        if(p[i].open) cnt++;
        if(cnt>mx) mx=cnt;
        if(p[i].open==false) cnt--;


        if(cnt==0){res+=(mx-1); mx=0; }

    }

    //res--;
    //if(res<1) res++;

    cout << res << endl;
}
