/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
int a[SIZE];
int cnt[SIZE];
int cc[SIZE];
int num[SIZE];
int dp_r[SIZE];
int l[SIZE],r[SIZE];
int n;
const int BIT_NUM = 20;
struct BIT{
    int _n;
    long long _d[1 << BIT_NUM];
    void init(int __n) {
        _n=__n;
        memset(_d, 0, sizeof(long long) * (_n+1));
    }
    void ins(int x, long long v) {
        for(; x <= _n; x += x & -x) { _d[x] = max(_d[x], v); }
    }
    long long qq(int x) {
        if(x <= 0) {
            return 0;
        }
        long long res = 0;
        for(; x; x -= x & -x) { res = max(res, _d[x]);}
        return res;
    }
}bit;
int rg[SIZE];
void solve() {
    int ma=0;
    FOR(i,1,n){
        l[i]=n+1;
    }
    for(int i=n;i>0;i--){
        l[a[i]]=min(l[a[i]],i);
        r[a[i]]=max(r[a[i]],i);
        cc[a[i]]++;
        cnt[a[i]]++;
        ma=max(ma,cnt[a[i]]);
        dp_r[i]=ma;
    }
    FOR(i,1,n){
        if(r[i]){
            num[r[i]]=cc[i];
            rg[r[i]]=l[i];
        }
    }
    bit.init(n);
    ma=0;
    FOR(i,1,n){
        if(rg[i]){
            int v=bit.qq(rg[i]-1)+num[i];
            //DEBUG(rg[i],i,v,cc[i]);
            ma=max(ma,v+dp_r[i+1]);
            bit.ins(i,v);
        }
    }
    W(n-ma);
}
void input() {
    R(n);
    FOR(i,1,n)R(a[i]);
}
int main(){
    input();
    solve();
    return 0;
}

### Prompt

Your task is to create a CPP solution to the following problem:

One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.

<image>

There are n books standing in a row on the shelf, the i-th book has color a_i.

You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.

In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.

What is the minimum number of operations you need to make the shelf beautiful?

Input

The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of books.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.

Output

Output the minimum number of operations to make the shelf beautiful.

Examples

Input


5
1 2 2 1 3


Output


2


Input


5
1 2 2 1 1


Output


1

Note

In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example: 

  1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1]; 
  2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1]. 



In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].

### Response

```cpp
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
int a[SIZE];
int cnt[SIZE];
int cc[SIZE];
int num[SIZE];
int dp_r[SIZE];
int l[SIZE],r[SIZE];
int n;
const int BIT_NUM = 20;
struct BIT{
    int _n;
    long long _d[1 << BIT_NUM];
    void init(int __n) {
        _n=__n;
        memset(_d, 0, sizeof(long long) * (_n+1));
    }
    void ins(int x, long long v) {
        for(; x <= _n; x += x & -x) { _d[x] = max(_d[x], v); }
    }
    long long qq(int x) {
        if(x <= 0) {
            return 0;
        }
        long long res = 0;
        for(; x; x -= x & -x) { res = max(res, _d[x]);}
        return res;
    }
}bit;
int rg[SIZE];
void solve() {
    int ma=0;
    FOR(i,1,n){
        l[i]=n+1;
    }
    for(int i=n;i>0;i--){
        l[a[i]]=min(l[a[i]],i);
        r[a[i]]=max(r[a[i]],i);
        cc[a[i]]++;
        cnt[a[i]]++;
        ma=max(ma,cnt[a[i]]);
        dp_r[i]=ma;
    }
    FOR(i,1,n){
        if(r[i]){
            num[r[i]]=cc[i];
            rg[r[i]]=l[i];
        }
    }
    bit.init(n);
    ma=0;
    FOR(i,1,n){
        if(rg[i]){
            int v=bit.qq(rg[i]-1)+num[i];
            //DEBUG(rg[i],i,v,cc[i]);
            ma=max(ma,v+dp_r[i+1]);
            bit.ins(i,v);
        }
    }
    W(n-ma);
}
void input() {
    R(n);
    FOR(i,1,n)R(a[i]);
}
int main(){
    input();
    solve();
    return 0;
}

```