#include <bits/stdc++.h>
using namespace std;
const bool DEBUG = 1;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, set<T> const& v) {
  for (auto i = v.begin(); i != v.end(); i++) out << (*i) << ' ';
  return out;
}
template <typename T, typename V>
ostream& operator<<(ostream& out, map<T, V> const& v) {
  for (auto i = v.begin(); i != v.end(); i++)
    out << "\n" << (i->first) << " : " << (i->second);
  return out;
}
template <typename T, typename V>
ostream& operator<<(ostream& out, unordered_map<T, V> const& v) {
  for (auto i = v.begin(); i != v.end(); i++)
    out << "\n" << (i->first) << " : " << (i->second);
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, multiset<T> const& v) {
  for (auto i = v.begin(); i != v.end(); i++) out << (*i) << ' ';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, unordered_set<T> const& v) {
  for (auto i = v.begin(); i != v.end(); i++) out << (*i) << ' ';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, unordered_multiset<T> const& v) {
  for (auto i = v.begin(); i != v.end(); i++) out << (*i) << ' ';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  long long l = v.size();
  for (long long i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, q;
  cin >> n >> q;
  vector<long long> arr(n);
  for (long long i = 0; i < n; i++) cin >> arr[i];
  unordered_map<long long, set<long long>> pre;
  for (long long i = 0; i < n; i++) pre[arr[i]].insert(i);
  long long ans = 0;
  long long l = 0;
  long long r = *pre[arr[0]].rbegin();
  long long i = 0;
  while (i < n) {
    if (*pre[arr[i]].begin() > r) {
      long long c = r - l + 1;
      long long mx = 0;
      for (long long j = l; j <= r; j++)
        mx = max(mx, (long long)pre[arr[j]].size());
      ans += c - mx;
      l = *pre[arr[i]].begin();
      r = *pre[arr[i]].rbegin();
    } else {
      r = max(r, *pre[arr[i]].rbegin());
    }
    i++;
  }
  long long c = r - l + 1;
  long long mx = 0;
  for (long long j = l; j <= r; j++)
    mx = max(mx, (long long)pre[arr[j]].size());
  ans += c - mx;
  cout << ans << "\n";
}
