#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 3, inf = 1e18, mod = 1e9 + 7, eps = -1e8;
long long tc, n, m, a, b, i, j, k, l, ans, mx, lft, rgt;
long long ar[N], cnt[N], last[N];
int32_t main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> ar[i];
    last[ar[i]] = i;
    cnt[ar[i]]++;
  }
  for (i = 1; i <= n; i++) {
    rgt = max(rgt, last[ar[i]]);
    mx = max(mx, cnt[ar[i]]);
    if (rgt == i) ans += i - lft - mx, mx = 0, lft = i;
  }
  cout << ans << endl;
}
