#include <bits/stdc++.h>
using namespace std;
const int maxx = 1000010;
int t, n, m, k, s;
int ans = 0, sum = 0, cnt = 0, total = 0, l = 0, r = 0;
int a[maxx], b[maxx], bj[maxx], mk[maxx], kl[maxx], fa[maxx], vis[maxx],
    siz[maxx], maxn[maxx];
int find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; i++) {
    scanf("%d", &a[i]), bj[a[i]]++;
    if (mk[a[i]] && a[i] != a[i - 1]) kl[a[i]] = 1;
    mk[a[i]] = i;
  }
  for (register int i = 1; i <= 200000; i++)
    fa[i] = i, maxn[i] = siz[i] = bj[i];
  for (register int i = 1; i <= n; i++) {
    if (r >= n) break;
    r = max(r, i);
    if (kl[a[i]]) {
      if (mk[a[i]] > r) {
        for (register int j = r + 1; j <= mk[a[i]]; j++) {
          int X = find(a[i]), Y = find(a[j]);
          if (X != Y) {
            fa[X] = Y;
            siz[Y] += siz[X];
            siz[X] = 0;
            maxn[Y] = max(maxn[Y], maxn[X]);
          }
        }
        r = mk[a[i]];
      }
    }
  }
  for (register int i = 1; i <= n; i++) {
    int X = find(a[i]);
    if (vis[X]) continue;
    vis[X] = 1;
    if (maxn[X] == siz[X]) continue;
    ans += siz[X] - maxn[X];
  }
  printf("%d", ans);
  return 0;
}
