#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char c = getchar();
  long long x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
long long n, a[200005], b[200005], m, Q, res;
struct node {
  long long l, r, x;
  bool operator<(const node& b) const { return l < b.l; }
} v[200005];
set<long long> s[200005];
signed main() {
  n = read(), Q = read();
  for (register long long i = (1); i <= (n); ++i) a[i] = b[++m] = read();
  sort(b + 1, b + m + 1), m = unique(b + 1, b + m + 1) - b - 1;
  for (register long long i = (1); i <= (n); ++i)
    a[i] = lower_bound(b + 1, b + m + 1, a[i]) - b, s[a[i]].insert(i);
  for (register long long i = (1); i <= (m); ++i)
    v[i].l = (*s[i].begin()), v[i].r = (*(--s[i].end())), v[i].x = s[i].size();
  sort(v + 1, v + m + 1);
  long long mx = 0, lst = 0;
  for (register long long i = (1); i <= (m); ++i) {
    mx = max(mx, v[i].r);
    if (i == m || mx < v[i + 1].l) {
      long long qwq = 0;
      for (register long long j = (lst + 1); j <= (i); ++j)
        qwq = max(qwq, v[j].x), res += v[j].x;
      res -= qwq;
      mx = 0, lst = i;
    }
  }
  cout << res;
  return 0;
}
