#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define el printf("\n");
#define pb push_back
int n;
int a[200001],dp[100001];
map<int,vector<int>> id;
int main() {
cin >> n;
for(int i=1;i<=n;i++) {
cin >> a[i];
id[a[i]].pb(i);
}
// dp[i] là số phần tử bị xóa đi nhiều nhất khi tính tới i
dp[0] = 0;
for(int i=1;i<=n;i++) {
dp[i] = dp[i-1];
for(int j=0;id[a[i]][j]<i;j++) {
dp[i] = max(dp[i],i-id[a[i]][j]+1+dp[id[a[i]][j]-1]);
}
}
cout << n-dp[n];
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgZWwgcHJpbnRmKCJcbiIpOwojZGVmaW5lIHBiIHB1c2hfYmFjawoKaW50IG47CmludCBhWzIwMDAwMV0sZHBbMTAwMDAxXTsKbWFwPGludCx2ZWN0b3I8aW50Pj4gaWQ7CgppbnQgbWFpbigpIHsKICAgIGNpbiA+PiBuOwogICAgZm9yKGludCBpPTE7aTw9bjtpKyspIHsKICAgICAgICBjaW4gPj4gYVtpXTsKICAgICAgICBpZFthW2ldXS5wYihpKTsKICAgIH0KICAgIC8vIGRwW2ldIGzDoCBz4buRIHBo4bqnbiB04butIGLhu4sgeMOzYSDEkWkgbmhp4buBdSBuaOG6pXQga2hpIHTDrW5oIHThu5tpIGkKICAgIGRwWzBdID0gMDsKICAgIGZvcihpbnQgaT0xO2k8PW47aSsrKSB7CiAgICAgICAgZHBbaV0gPSBkcFtpLTFdOwogICAgICAgIGZvcihpbnQgaj0wO2lkW2FbaV1dW2pdPGk7aisrKSB7CiAgICAgICAgICAgIGRwW2ldID0gbWF4KGRwW2ldLGktaWRbYVtpXV1bal0rMStkcFtpZFthW2ldXVtqXS0xXSk7CiAgICAgICAgfQogICAgfQogICAgY291dCA8PCBuLWRwW25dOwogICAgcmV0dXJuIDA7Cn0=