#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <vector>
using namespace std;

/// START Errichto's debug
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
/// END Errichto's debug

#define ff first
#define ss second
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define f0(i, n) for(auto i = 0; i < n; ++i)
#define fo(i, k, n) for(auto i = k; i < n; ++i)
#define foo(i, a, b, k) for(auto i = a; i < b; i += k)
#define rf0(n, i) for(auto i = n-1; ~i; --i)
#define rfo(n, k, i) for(auto i = n-1; i >= k; --i)
#define rfoo(b, a, k, i) for(auto i = b; i > a; i -= k)
#define Im_speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef long double ld;
typedef uint32_t uint;
typedef int64_t ll;
typedef uint64_t ull;

//ifstream fin("date.in");
//ofstream fout("date.out");

const int nax = 1e5 + 3;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll infll = 1e18 + 7;
const ld PI = 3.1415926535897932384626433832795;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), fr(n, 0);
    vector<pair<int, int>> pos(n, {inf, 0});
    f0(i, n) {
        cin >> a[i]; --a[i];
        if(pos[a[i]].ff == inf) {
            pos[a[i]].ff = i;
        }
        pos[a[i]].ss = i;
        ++fr[a[i]];
    }

    vector<int> dp(n+1, 0), currfr(n, 0);
    rf0(n, i) {
        dp[i] = dp[i+1];
        ++currfr[a[i]];
        if(i == pos[a[i]].ff) {
            dp[i] = max(dp[i], dp[pos[a[i]].ss + 1] + fr[a[i]]);
        }
        else {
            dp[i] = max(dp[i], currfr[a[i]]);
        }
    }
    cout << n - dp[0];
}

int main() {
//    clock_t _clock = clock();
    Im_speed;
    cout << fixed << setprecision(12);

    int t = 1;
//    cin >> t;
    while(t--) {
        solve();
    }

//    cout << ((((double) clock()) - ((double)_clock)) / ((double) CLK_TCK));
}
