#include <bits/stdc++.h>
using namespace std;
struct Dout {
  Dout() noexcept {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  }
} dout;
template <typename T>
Dout operator<<(Dout d, T t) {
  return d;
}
int most_common_count(vector<int> const &v, int l, int r) {
  map<int, int> cnt;
  for (int i = l; i <= r; i++) {
    cnt[v[i]]++;
  }
  int ans = 0;
  for (auto q : cnt) {
    ans = max(ans, q.second);
  }
  return ans;
}
int main() {
  int n, t;
  cin >> n >> t;
  map<int, pair<int, int> > q;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v[i] = a;
    if (q[a].first == q[a].second) {
      q[a].first = i;
      q[a].second = -1;
    } else {
      q[a].second = i;
    }
  }
  string psp;
  psp.resize(n, 'x');
  for (auto w : q) {
    if (w.second.second != -1) {
      psp[w.second.first] = '(';
      psp[w.second.second] = ')';
    }
  }
  int bal = 0;
  int prev = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (psp[i] == '(') {
      if (bal == 0) {
        prev = i;
      }
      bal++;
    } else if (psp[i] == ')') {
      bal--;
      if (bal == 0) {
        ans += i + 1 - prev - most_common_count(v, prev, i);
      }
    }
  }
  cout << ans;
}
