#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
int a, b, c, d, n, m, k;
int mas[200002];
pair<int, int> sg[200002];
int pr[200002];
inline int p(int a) {
  if (pr[a] == -1) return a;
  return pr[a] = p(pr[a]);
}
int cc[200002], mx[200002], cs[200002];
inline void un(int a, int b) {
  if (a == -1 || b == -1) return;
  a = p(a);
  b = p(b);
  if (a != b) {
    pr[b] = a;
    mx[a] = max(mx[a], mx[b]);
    cs[a] += cs[b];
  }
}
void rec(int l, int r, int pr) {
  if (l >= r) return;
  if (pr != -1) {
    for (int _n(r - 1), i(l); i <= _n; i++) {
      un(pr, mas[i]);
    }
    return;
  }
  if (l == r - 1) return;
  int xx = (r + l) / 2;
  int n1 = -1, n2 = -1, n3 = -1;
  for (int _n(r - 1), i(l); i <= _n; i++) {
    int v = mas[i];
    if (sg[v].first <= l && sg[v].second >= xx - 1) {
      if (sg[v].first >= l && sg[v].second <= xx - 1) continue;
      if (i >= l && i <= xx - 1) {
        if (sg[v].first < l)
          n1 = v;
        else if (sg[v].second > xx - 1)
          n2 = v;
      } else {
        if (sg[v].first < l) {
          n3 = v;
        }
      }
    }
  }
  un(n1, n2);
  un(n1, n3);
  un(n2, n3);
  int nn = max(n1, max(n2, n3));
  rec(l, xx, nn);
  n1 = -1;
  n2 = -1;
  n3 = -1;
  for (int _n(r - 1), i(l); i <= _n; i++) {
    int v = mas[i];
    if (sg[v].first <= xx && sg[v].second >= r - 1) {
      if (sg[v].first >= xx && sg[v].second <= r - 1) continue;
      if (i >= xx && i <= r - 1) {
        if (sg[v].first < xx)
          n1 = v;
        else if (sg[v].second > r - 1)
          n2 = v;
      } else {
        if (sg[v].second > r - 1) {
          n3 = v;
        }
      }
    }
  }
  un(n1, n2);
  un(n1, n3);
  un(n2, n3);
  nn = max(n1, max(n2, n3));
  rec(xx, r, nn);
}
vector<int> bsm[102];
bool bu[102];
pair<int, int> bdfs(int v) {
  pair<int, int> tt = make_pair(cc[v], cc[v]);
  bu[v] = 1;
  for (int _n(((int)((bsm[v]).size())) - 1), i(0); i <= _n; i++) {
    int w = bsm[v][i];
    if (bu[w]) continue;
    auto t = bdfs(w);
    tt.first += t.first;
    tt.second = max(tt.second, t.second);
  }
  return tt;
}
int brute() {
  for (int _n((100) - 1), i(0); i <= _n; i++) bsm[i].clear();
  for (int _n((n)-1), i(0); i <= _n; i++) {
    for (int _n(n - 1), j(i + 1); j <= _n; j++) {
      if (mas[i] != mas[j]) continue;
      for (int _n(j - 1), z(i + 1); z <= _n; z++) {
        bsm[mas[i]].push_back(mas[z]);
        bsm[mas[z]].push_back(mas[i]);
      }
    }
  }
  int ans = 0;
  memset((bu), 0, sizeof(bu));
  for (int _n((100)), i(1); i <= _n; i++) {
    if (!bu[i]) {
      pair<int, int> tt = bdfs(i);
      ans += tt.first - tt.second;
    }
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(sg, -1, sizeof(sg));
  memset(pr, -1, sizeof(pr));
  memset((cc), 0, sizeof(cc));
  for (int _n((n)-1), i(0); i <= _n; i++) {
    scanf("%d", &mas[i]);
    if (sg[mas[i]].first == -1) sg[mas[i]].first = i;
    sg[mas[i]].second = i;
    ++cc[mas[i]];
  }
  for (int _n((200000)), i(1); i <= _n; i++) mx[i] = cc[i], cs[i] = cc[i];
  k = 0;
  rec(0, n, -1);
  int ans = 0;
  for (int _n((200000)), i(1); i <= _n; i++) {
    if (pr[i] != -1) continue;
    ans += cs[i];
    ans -= mx[i];
  }
  printf("%d\n", ans);
}
