#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -f;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  x *= f;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (!x) return;
  print(x / 10), putchar(x % 10 + 48);
}
void write(int x) {
  if (!x)
    putchar('0');
  else
    print(x);
  putchar('\n');
}
const int maxn = 1e6 + 10;
const int inf = 1e9;
const double eps = 1e-8;
const int mod = 1e9 + 7;
int n, a[maxn], top, s[maxn];
struct data {
  int l, r;
} t[maxn], sta[maxn];
int cmp(data aa, data b) { return aa.r < b.r; }
int main() {
  read(n), read(a[0]);
  for (int i = 1; i <= n; i++)
    read(a[i]), t[a[i]].r = i, t[a[i]].l = (t[a[i]].l ? t[a[i]].l : i);
  sort(t + 1, t + 200000 + 1, cmp);
  for (int i = 1; i <= 200000; i++) {
    if (!t[i].l) continue;
    while (t[i].l < sta[top].r) t[i].l = min(t[i].l, sta[top].l), top--;
    sta[++top] = t[i];
  }
  int ans = 0;
  for (int x = 1; x <= top; x++) {
    int res = 0;
    for (int i = sta[x].l; i <= sta[x].r; i++) res = max(res, ++s[a[i]]), ans++;
    ans -= res;
    for (int i = sta[x].l; i <= sta[x].r; i++) s[a[i]] = 0;
  }
  write(ans);
  return 0;
}
