#include <bits/stdc++.h>
using namespace std;
const int INF = (int)(1e9 + 1337);
const long long LINF = (long long)(4e18);
const double EPS = (double)(1e-7);
int n, q;
vector<int> a;
unordered_map<int, int> mx;
unordered_map<int, int> mn;
unordered_map<int, int> ct;
vector<vector<int> > g;
vector<int> c;
void dfs(int v, int nc, int& maj, int& total) {
  c[v] = nc;
  maj = max(maj, ct[v]);
  total += ct[v];
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (c[to] != -1) {
      continue;
    }
    dfs(to, nc, maj, total);
  }
}
void solve() {
  cin >> n >> q;
  a.resize(n);
  int gmx = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    gmx = max(gmx, a[i]);
    mx[a[i]] = i;
    if (!mn.count(a[i])) {
      mn[a[i]] = i;
    }
    ++ct[a[i]];
  }
  g.resize(gmx + 1);
  c.assign(gmx + 1, -1);
  unordered_set<int> st;
  for (int i = 0; i + 1 < n; ++i) {
    if (mn[a[i]] == i) {
      st.insert(a[i]);
    }
    if (mx[a[i]] == i) {
      st.erase(a[i]);
    }
    if (!st.empty()) {
      g[a[i]].push_back(*st.begin());
      g[*st.begin()].push_back(a[i]);
    }
  }
  int ans = 0;
  for (const auto& it : mx) {
    int x = it.first;
    if (c[x] != -1) {
      continue;
    }
    int maj = 0;
    int total = 0;
    dfs(x, x, maj, total);
    ans += total - maj;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
