#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, j, n) for (ll i = j; i < (n); ++i)
#define rrep(i, j, n) for (ll i = (n)-1; j <= i; --i)

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& a) {
  for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? " " : "") << a[i];
  return os << '\n';
}

[[maybe_unused]] constexpr ll MOD = 998244353;
[[maybe_unused]] constexpr int INF = 0x3f3f3f3f;
[[maybe_unused]] constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n), freq(n), tfreq(n);
  vector<pair<int, int>> pos(n, {-1, -1});
  rep(i, 0, n) {
    cin >> a[i];
    --a[i];
    freq[a[i]]++;
    if (pos[a[i]].first == -1)
      pos[a[i]] = {i, i};
    else
      pos[a[i]].second = i;
  }
  vector<int> dp(n + 1);
  rrep(i, 0, n) {
    // move a[i]
    dp[i] = dp[i + 1];
    int r = pos[a[i]].second;
    tfreq[a[i]]++;
    // element between [l, r] should be moved, but not [r+1, n)
    if (i == pos[a[i]].first)
      dp[i] = max(dp[i], dp[r + 1] + freq[a[i]]);
    else
      // color a[i] should be backmost
      dp[i] = max(dp[i], tfreq[a[i]]);
  }
  cout << n - dp[0] << '\n';
  return 0;
}
