#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
using namespace std;
const int mex=2e5+5;
vector<int>par(mex), sz(mex, 0), idx(mex, -1*mod);
void init(int n){
    for(int i=0; i<n; i++) par[i]=i;
}
int find_par(int x){
    if(x==par[x]) return x;
    return par[x]=find_par(par[x]);
}
void union_set(int x, int y){
    x=find_par(x);
    y=find_par(y);
    if(x==y) return ;
    if (sz[x]<sz[y]) swap(x, y);
    sz[x]+=sz[y];
    par[y]=x;
}
main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, ans;
    cin>>n>>ans;
    vector<int>arr(n);
    init(mex);
    for(int i=0; i<n; i++){
        cin>>arr[i];
        idx[arr[i]]=max(idx[arr[i]], i);
        sz[arr[i]]++;
    }
    int cur=arr[0];
    for(int i=1; i<n; i++){
        if(idx[cur]<i) cur=arr[i];
        if(find_par(cur)==find_par(arr[i])) continue;
        idx[cur]=max(idx[cur], idx[arr[i]]);
        idx[arr[i]]=idx[cur];
        ans+=min(sz[arr[i]], sz[cur]);
        union_set(cur, arr[i]);
        cur=find_par(arr[i]);
    }
    cout<<ans<<endl;

}


#include<bits/stdc++.h>
#define pb push_back
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
using namespace std;
const int mex=2e5+5;
int ans;
vector<int>sz(mex, 0), idx(mex, -1*mod);
main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n>>ans;
    vector<int>arr(n);
    for(int i=0; i<n; i++){
        cin>>arr[i];
        idx[arr[i]]=max(idx[arr[i]], i);
        sz[arr[i]]++;
    }
    int cur=0, last=0;
    priority_queue<int>pq;
    for(int i=0; i<n; i++){
        if(cur<i){
            ans+=i-last-pq.top();
            last=i;
            while(!pq.empty()) pq.pop();
        }
        cur=max(cur, idx[arr[i]]);
        pq.push(sz[arr[i]]);
    }
    ans+=n-last-pq.top();
    cout<<ans<<endl;

}


#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
using namespace std;
const int mex=2e5+5;
int ans;
vector<int>sz(mex, 0), idx(mex, -1*mod);
main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n>>ans;
    vector<int>arr(n);
    map<int, int>m;
    for(int i=0; i<n; i++){
        cin>>arr[i];
        idx[arr[i]]=max(idx[arr[i]], i);
        sz[arr[i]]++;
    }
    int cur=0, last=0;
    priority_queue<int>pq;
    for(int i=0; i<n; i++){
        if(cur<i){
            int st=m.begin()->S;
            ans+=i-last-pq.top();
            last=i;
            while(!pq.empty()) pq.pop();
        }
        cur=max(cur, idx[arr[i]]);
        pq.push(sz[arr[i]]);
    }
    ans+=n-1-last+1-pq.top();
    cout<<ans<<endl;

}


#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
using namespace std;
const int mex=2e5+5;
int ans;
vector<int>par(mex), sz(mex, 0), idx(mex, -1*mod);
void init(int n){
    for(int i=0; i<n; i++) par[i]=i;
}
int find_par(int x){
    if(x==par[x]) return x;
    return par[x]=find_par(par[x]);
}
void union_set(int x, int y){
    x=find_par(x);
    y=find_par(y);
    if(x==y) return ;
    if (sz[x]<sz[y]) swap(x, y);
    sz[x]+=sz[y];
    ans+=sz[y];
    par[y]=x;
}
main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n>>ans;
    vector<int>arr(n);
    init(mex);
    for(int i=0; i<n; i++){
        cin>>arr[i];
        idx[arr[i]]=max(idx[arr[i]], i);
        sz[arr[i]]++;
    }
    int cur=arr[0];
    for(int i=1; i<n; i++){
        if(idx[cur]<i) cur=arr[i];
        int prev=cur;
        if(find_par(cur)==find_par(arr[i])) continue;
        union_set(cur, arr[i]);
        cur=find_par(arr[i]);
        idx[cur]=max(idx[prev], idx[arr[i]]);
    }
    cout<<ans<<endl;

}


#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
using namespace std;
const int mex=2e5+5;
vector<int>par(mex), sz(mex, 0), idx(mex, -1*mod);
void init(int n){
    for(int i=0; i<n; i++) par[i]=i;
}
int find_par(int x){
    if(x==par[x]) return x;
    return par[x]=find_par(par[x]);
}
void union_set(int x, int y){
    x=find_par(x);
    y=find_par(y);
    if(x==y) return ;
    if (sz[x]<sz[y]) swap(x, y);
    sz[x]+=sz[y];
    par[y]=x;
}
main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, ans;
    cin>>n>>ans;
    vector<int>arr(n);
    init(mex);
    for(int i=0; i<n; i++){
        cin>>arr[i];
        idx[arr[i]]=max(idx[arr[i]], i);
        sz[arr[i]]++;
    }
    int cur=arr[0];
    for(int i=1; i<n; i++){
        if(idx[cur]<i) cur=arr[i];
        if(find_par(cur)==find_par(arr[i])) continue;
        union_set(cur, arr[i]);
        ans+=min(sz[arr[i]], sz[cur]);
    }
    cout<<ans<<endl;

}


#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
using namespace std;
const int mex=2e5+5;
vector<int>par(mex), sz(mex, 0), idx(mex, -1*mod);
void init(int n){
    for(int i=0; i<n; i++) par[i]=i;
}
int find_par(int x){
    if(x==par[x]) return x;
    return par[x]=find_par(par[x]);
}
void union_set(int x, int y){
    x=find_par(x);
    y=find_par(y);
    if(x==y) return ;
    if (sz[x]<sz[y]) swap(x, y);
    sz[x]+=sz[y];
    par[y]=x;
}
main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, ans;
    cin>>n>>ans;
    vector<int>arr(n);
    init(mex);
    for(int i=0; i<n; i++){
        cin>>arr[i];
        idx[arr[i]]=max(idx[arr[i]], i);
        sz[arr[i]]++;
    }
    int cur=arr[0];
    for(int i=1; i<n; i++){
        if(idx[cur]<i) cur=arr[i];
        int id=idx[cur];
        if(find_par(cur)==find_par(arr[i])) continue;
        idx[cur]=max(idx[cur], idx[arr[i]]);
        idx[arr[i]]=idx[cur];
        union_set(cur, arr[i]);
        cur=find_par(cur);
        ans+=min(sz[arr[i]], sz[cur]);
    }
    cout<<ans<<endl;

}


#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
using namespace std;
const int mex=2e5+5;
vector<int>par(mex), sz(mex, 0), idx(mex, -1*mod);
void init(int n){
    for(int i=0; i<n; i++) par[i]=i;
}
int find_par(int x){
    if(x==par[x]) return x;
    return par[x]=find_par(par[x]);
}
void union_set(int x, int y){
    x=find_par(x);
    y=find_par(y);
    if(x==y) return ;
    if (sz[x]<sz[y]) swap(x, y);
    sz[x]+=sz[y];
    par[y]=x;
}
main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, ans;
    cin>>n>>ans;
    vector<int>arr(n);
    init(mex);
    for(int i=0; i<n; i++){
        cin>>arr[i];
        idx[arr[i]]=max(idx[arr[i]], i);
        sz[arr[i]]++;
    }
    int cur=arr[0];
    for(int i=1; i<n; i++){
        if(idx[cur]<i) cur=arr[i];
        if(find_par(cur)==find_par(arr[i])) continue;
        idx[cur]=max(idx[cur], idx[arr[i]]);
        idx[arr[i]]=idx[cur];
        union_set(cur, arr[i]);
        ans+=min(sz[arr[i]], sz[cur]);
        cur=find_par(cur);
    }
    cout<<ans<<endl;

}


#include <bits/stdc++.h>
using namespace std;

void run();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}

void run(){
    int n, q, maxn = 2e5 + 1;
    cin >> n >> q;
    vector <int> v(n), bound(maxn, -1);
    for (int i = 0; i < n; i++){
        cin >> v[i];
        bound[v[i]] = max(bound[v[i]], i);
    }
    int right = -1, base = -1, ans = 0;
    for (int i = 0; i < n; i++){
        if (i > right)
            base = v[i];
        right = max(right, bound[v[i]]);
        ans += base != v[i];
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;

void run();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}

void run(){
    int n, q, maxn = 2e5 + 1;
    cin >> n >> q;
    vector <int> v(n), bound(maxn, -1), cnt(maxn);
    for (int i = 0; i < n; i++){
        cin >> v[i];
        bound[v[i]] = max(bound[v[i]], i);
        cnt[v[i]]++;
    }
    int left = 0, right = 0, base = 0, ans = 0;
    for (int i = 0; i < n + 1; i++){
        if (i > right){
            ans += (right - left + 1 - base);
            left = i;
            base = 0;
        }
        if (i < n){
            right = max(right, bound[v[i]]);
            base = max(base, cnt[v[i]]);
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;

void run();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}

void run(){
    int n, q, maxn = 2e5 + 1;
    cin >> n >> q;
    vector <int> v(n), bound(maxn, -1), cnt(maxn);
    for (int i = 0; i < n; i++){
        cin >> v[i];
        bound[v[i]] = max(bound[v[i]], i);
        cnt[v[i]]++;
    }
    int left = 0, right = 0, base = 0, ans = 0;
    for (int i = 0; i < n + 1; i++){
        if (i > right){
            ans += (right - left + 1 - base);
            left = i;
        }
        if (i < n){
            right = max(right, bound[v[i]]);
            base = max(base, cnt[v[i]]);
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
using namespace std;

int N, x, y, muie;
vector <int> A;
vector <pii> B(200005);
vector <pii> V;
int Mars[200005];
int ap[200005];
pii unite (pii a, pii b) {
    if (a.first > b.first) swap(a, b);
    if (b.first > a.second) return {-1, -1};
    return {a.first, max(a.second, b.second)};
}
int f (pii pe) {
    int Mx = -1;
    for (int i = pe.first; i <= pe.second; ++i)
        Mx = max (Mx, ap[A[i]]);
    return pe.second - pe.first + 1 - Mx;
}
int main() {
    cin >> N >> muie;
    A.pb(0);
    for (int i = 1; i <= N; ++i) {
        cin >> x;
        A.pb(x);
        ++ap[x];
        if (B[x].first == 0) B[x].first = i;
        else B[x].second = i;
    }
    for (int i = 1; i <= 200000; ++i) {
        if (B[i].first && B[i].second) {
           V.pb(B[i]);
        }
    }
    sort(V.begin(), V.end());
    reverse(V.begin(), V.end());
    int sol = 0;
    while (!V.empty()) {
        pii pe = V.back();
        V.pop_back();
        if (V.empty()) {
            sol = sol + f(pe);
            cout << sol << '\n';
            return 0;
        }
        pii pe2 = V.back();
        V.pop_back();
        pii res = unite (pe, pe2);
        if (res == mp(-1, -1) ) {
            sol += f(pe);
            V.push_back(pe2);
        }
        else V.push_back(res);
    }
    cout << 0;
    return 0;
}


#include <bits/stdc++.h>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
using namespace std;

int N, x, y, muie;
vector <int> A;
vector <pii> B(200005);
vector <pii> V;
int Mars[200005];
int ap[200005];
pii unite (pii a, pii b) {
    if (a.first > b.first) swap(a, b);
    if (b.first > a.second) return {-1, -1};
    return {a.first, max(a.second, b.second)};
}
int f (pii pe) {
    int Mx = -1;
    for (int i = pe.first; i <= pe.second; ++i)
        Mx = max (Mx, ap[A[i]]);
    return pe.second - pe.first + 1 - Mx;
}
int main() {
    cin >> N >> muie;
    A.pb(0);
    for (int i = 1; i <= N; ++i) {
        cin >> x;
        A.pb(x);
        ++ap[x];
        if (B[x].first == 0) B[x].first = i;
        else B[x].second = i;
    }
    for (int i = 1; i <= 200000; ++i) {
        if (B[i].first && B[i].second) {
           V.pb(B[i]);
        }
    }
    sort(V.begin(), V.end());
    reverse(V.begin(), V.end());
    int sol = 0;
    while (!V.empty()) {
        pii pe = V.back();
        V.pop_back();
        if (V.empty()) {
            sol = sol + f(pe);
            cout << sol << '\n';
            return 0;
        }
        pii pe2 = V.back();
        V.pop_back();
        pii res = unite (pe, pe2);
        if (res == mp(-1, -1) ) {
            sol += f(pe);
            V.push_back(pe2);
        }
        else V.push_back(res);
    }
    return 0;
}


#include <bits/stdc++.h>
#define pii pair <int, int>
#define pb push_back
using namespace std;

int N, x, y, muie;
vector <int> A;
vector <pii> B(200005);
int Mars[200005];
int ap[200005];
int main() {
    cin >> N >> muie;
    for (int i = 1; i <= N; ++i) {
        cin >> x;
        A.pb(x);
        ++ap[x];
        if (B[x].first == 0) B[x].first = i;
        else B[x].second = i;
    }
    for (int i = 1; i <= 200000; ++i) {
        if (B[i].first && B[i].second) {
            //cout << B[i].first << ' ' << B[i].second << '\n';
            ++Mars[B[i].first];
            --Mars[B[i].second + 1];
        }
    }
    for (int i = 2; i <= 200000; ++i) {
        Mars[i] += Mars[i - 1];
    }
    int sol = 0, i, j;
    i = 1;
    while (i <= N) {
        if (Mars[i] > 0) {
            j = i;
            int Max = -1;
            while (Mars[j] > 0 && j <= N) {
                Max = max(Max, ap[A[j]]);
                ++j;
            }
            sol = sol + (j - i ) - Max;
        }
        i = j + 1;
    }
    cout << sol;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define out(x) cout<<setprecision(15)<<x<<endl,exit(0);
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second
#define ld long double
ld pi=3.14159265359;

const int N=2e5+3;
int a[N],fst[N],lst[N],ans,prv=1,r;
vector <pii> v;

void slv(){
	map <int,int> mp;
	int mx=0;
	F(j,prv,r) mp[a[j]]++;
	for(auto it:mp) mx=max(mx,it.S);

	ans+=r-prv+1-mx;
	prv=r+1;
}

int32_t main(){
	ios;
	int n,q;
	cin>>n>>q;

	F(i,1,n){
		cin>>a[i];
	}
	F(i,1,n) lst[a[i]]=i;
	R(i,n,1) fst[a[i]]=i;

	F(i,1,N-1) if(lst[i]) v.pb({fst[i],lst[i]});
	sort(all(v));

	int prv=1,r=0;
	F(i,0,v.size()-1){
		if(v[i].I>r) slv();
		r=max(r,v[i].S);
	}
	slv();

	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define out(x) cout<<setprecision(15)<<x<<endl,exit(0);
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second
#define ld long double
ld pi=3.14159265359;

const int N=2e5+3;
int a[N],fst[N],lst[N],ans,prv=1,r;
vector <pii> v;

void slv(){
	map <int,int> mp;
	int mx=0;
	F(j,prv,r) mp[a[j]]++;
	for(auto it:mp) mx=max(mx,it.S);

	ans+=r-prv+1-mx;
	prv=r+1;
}

int32_t main(){
	ios;
	int n,q;
	cin>>n>>q;

	F(i,1,n){
		cin>>a[i];
	}
	F(i,1,n) lst[a[i]]=i;
	R(i,n,1) fst[a[i]]=i;

	F(i,1,N-1) if(lst[i]) v.pb({fst[i],lst[i]});
	sort(all(v));

	F(i,0,v.size()-1){
		if(v[i].I>r) slv();
		r=max(r,v[i].S);
	}
	slv();

	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define out(x) cout<<setprecision(15)<<x<<endl,exit(0);
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second
#define ld long double
ld pi=3.14159265359;

const int N=2e5+3;
int a[N],fst[N],lst[N],ans;
vector <pii> v;

int32_t main(){
	ios;
	int n,q;
	cin>>n>>q;

	F(i,1,n){
		cin>>a[i];
	}
	F(i,1,n) lst[a[i]]=i;
	R(i,n,1) fst[a[i]]=i;

	F(i,1,N-1){
		if(lst[i]){
			v.pb({fst[i],lst[i]});
		}
	}
	sort(all(v));

	//for(auto it:v) cout<<it.I<<" "<<it.S<<endl;
	int prv=1,r=0;
	F(i,0,v.size()-1){
		if(v[i].I>r){
			map <int,int> mp;
			int mx=0;
			F(j,prv,r) mp[a[j]]++;
			for(auto it:mp) mx=max(mx,it.S);

			ans+=r-prv+1-mx;
			prv=r+1;
		}
		r=max(r,v[i].S);
	}
	map <int,int> mp;
	int mx=0;
	F(j,prv,r) mp[a[j]]++;
	for(auto it:mp) mx=max(mx,it.S);

	ans+=r-prv+1-mx;
	prv=r+1;

	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define out(x) cout<<setprecision(15)<<x<<endl,exit(0);
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second
#define ld long double
ld pi=3.14159265359;

const int N=2e5+3;
int a[N],fst[N],lst[N],ans;
vector <pii> v;

void slv(int prv,int r){
	map <int,int> mp;
	int mx=0;
	F(j,prv,r) mp[a[j]]++;
	for(auto it:mp) mx=max(mx,it.S);

	ans+=r-prv+1-mx;
	prv=r+1;
}

int32_t main(){
	ios;
	int n,q;
	cin>>n>>q;

	F(i,1,n){
		cin>>a[i];
	}
	F(i,1,n) lst[a[i]]=i;
	R(i,n,1) fst[a[i]]=i;

	F(i,1,N-1) if(lst[i]) v.pb({fst[i],lst[i]});
	sort(all(v));

	int prv=1,r=0;
	F(i,0,v.size()-1){
		if(v[i].I>r) slv(prv,r);
		r=max(r,v[i].S);
	}
	slv(prv,r);

	cout<<ans;
}


#include<iostream>
#include<algorithm>
using namespace std;

int a[200010];
int num[200010];
int nxt[200010];
int pre[200010];

int main() {
	int n, t; cin >> n >> t;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 1; i <= n; i++) {
		if (pre[a[i]] != 0)nxt[pre[a[i]]] = i;
		pre[a[i]] = i;
		num[a[i]]++;
	}
	int ans = 0;
	int p = 1, q = nxt[1];
	while (p <= n) {
		if (q == 0) {
			p++;
			continue;
		}
		for (int i = p; i <= q; i++) {
			q = max(q, nxt[i]);
		}
		int maxn = 0;
		for (int i = p; i <= q; i++) {
			maxn = max(maxn, num[a[i]]);
		}
		ans += q - p + 1 - maxn;
		//cout << p << " " << q << endl;
		p = q + 1; q = nxt[p];
	}
	cout << ans << endl;
}


#include<iostream>
#include<algorithm>
using namespace std;

int a[200010];
int num[200010];
int nxt[200010];
int pre[200010];

int main() {

	int n, t; cin >> n >> t;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 1; i <= n; i++) {
		if (pre[a[i]] != 0)nxt[pre[a[i]]] = i;
		pre[a[i]] = i;
		num[a[i]]++;
	}
	//for (int i = 1; i <= n; i++)cout << i << " " << nxt[i] << endl;

	int ans = 0;
	int p = 1, q = nxt[1];
	while (p <= n) {

		if (q == 0) {
			p++; q = nxt[p];
			continue;
		}

		for (int i = p; i <= q; i++) {
			q = max(q, nxt[i]);
		}
		int maxn = 0;
		for (int i = p; i <= q; i++) {
			maxn = max(maxn, num[a[i]]);
		}
		ans += q - p + 1 - maxn;
		//cout << p << " " << q << endl;
		p = q + 1; q = nxt[p];
	}
	cout << ans << endl;
}


#include<iostream>
#include<algorithm>
using namespace std;

int a[200010];
int num[200010];
int nxt[200010];
int pre[200010];

int main() {

	int n, t; cin >> n >> t;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 1; i <= n; i++) {
		if (pre[a[i]] != 0)nxt[pre[a[i]]] = i;
		pre[a[i]] = i;
		num[a[i]]++;
	}

	int ans = 0;
	int p = 1, q = nxt[1];
	while (p <= n + 1) {
		if (q == 0) {
			p++;
			continue;
		}

		for (int i = p; i <= q; i++) {
			q = max(q, nxt[i]);
		}
		int maxn = 0;
		for (int i = p; i <= q; i++) {
			maxn = max(maxn, num[a[i]]);
		}
		ans += q - p + 1 - maxn;
		//cout << p << " " << q << endl;
		p = q + 1; q = nxt[p];
	}
	cout << ans << endl;
}


#include<iostream>
#include<algorithm>
using namespace std;

int a[200010];
int num[200010];
int nxt[200010];
int pre[200010];

int main() {

	int n, t; cin >> n >> t;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 1; i <= n; i++) {
		if (pre[a[i]] != 0)nxt[pre[a[i]]] = i;
		pre[a[i]] = i;
		num[a[i]]++;
	}

	int ans = 0;
	int p = 1, q = nxt[1];

	while (p < n) {
		if (q == 0) {
			p++;
			continue;
		}
		for (int i = p; i <= q; i++) {
			q = max(q, nxt[i]);
		}
		int maxn = 0;
		for (int i = p; i <= q; i++) {
			maxn = max(maxn, num[a[i]]);
		}
		ans += q - p + 1 - maxn;
		//cout << p << " " << q << endl;
		p = q + 1; q = nxt[p];
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define p pair<ll,ll>
int LIM=2e5+10;
v first(LIM);
v tree(2*LIM,0);
int n;
int combine(int a,int b)
{
    return min(a,b);
}
void update(int pos,int value,v &tree)
{
    pos+=n-1;
    tree[pos]=value;
    pos=pos/2;
    while (pos>=1)
    {
        tree[pos]=combine(tree[2*pos],tree[2*pos+1]);
        pos=pos/2;
    }
}
int query(int l,int r, v&tree)
{
    l+=n-1;
    r+=n-1;
    ll ans=1e9;
    while (l<=r)
    {
        if (l%2==1)
        {
            ans=combine(ans,tree[l]);
            l++;
        }
        if (r%2==0)
        {
            ans=combine(ans,tree[r]);
            r--;
        }
        l=l/2;
        r=r/2;
    }
    return ans;
}
int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    cin>>n>>q;
    v arr(n+1,0);
    v last(LIM,-1);
    v count(LIM,0);
    for (int i=1; i<=n;i++)
    {
    	cin>>arr[i];
    	if (last[arr[i]]==-1)
    	{
    		first[i]=i;
    	}
    	else
    	{
    		first[i]=last[arr[i]];
    	}
    	last[arr[i]]=i;
    	update(i,first[i],tree);
    }
    v dp(n+1,0);
    for (int i=1; i<=n; i++)
    {
        count[arr[i]]++;
    	int temp=query(first[i],i,tree);
    	ll t1=(i-temp+1)-count[arr[i]];
    	dp[i]=min(dp[i-1]+count[arr[i]],dp[temp-1]+t1);
    }
    cout<<dp[n]<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
int LIM=2e5+10;
int n;
int main() {
    int q,i=1;
    cin>>n>>q;
    ll ans=0;
    v last(n+1,0),arr(n+1,0),count(LIM,0);
    for (int i=1; i<=n; i++)
    {
        cin>>arr[i];
        last[arr[i]]=i;
        count[arr[i]]++;
    }
    while (i<=n)
    {
        int start=i;
        ll b=0;
        ll maxi=last[arr[i]];
        for (; i<=maxi; i++)
        {
            maxi=max(maxi,last[arr[i]]);
            b=max(b,count[arr[i]]);
        }
        ans+=i-start-b;
    }
    cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define p pair<ll,ll>
int LIM=2e5+10;
int n;
int main() {
    int q,i=1;
    cin>>n>>q;
    ll ans=0;
    v last(n+1,0),arr(n+1,0),count(LIM,0);
    for (int i=1; i<=n; i++)
    {
        cin>>arr[i];
        last[arr[i]]=i;
        count[arr[i]]++;
    }
    while (i<=n)
    {
        int start=i;
        ll b=0;
        ll maxi=last[arr[i]];
        for (; i<=maxi; i++)
        {
            maxi=max(maxi,last[arr[i]]);
            b=max(b,count[arr[i]]);
            // cout<<i<<" "<<maxi<<endl;
        }
        ans+=i-start-b;
        // cout<<i<<" "<<b<<"a"<<" "<<ans<<" "<<n<<endl;
    }
    cout<<ans<<endl;
    // cout<<"b"<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> gr [100001];
vector<bool> visit;
int myCount;

void dfs(int i) {
    visit[i] = true;
    myCount++;
    for (int v : gr[i]) {
        if (!visit[v])
            dfs(v);
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a;
    vector<int> was;
    vector<int> count;
    was = vector<int>(200000);
    fill(was.begin(), was.end(), -1);
    for (int i = 0; i < n; i++) {
        int a1;
        cin >> a1;
        was[a1] = i;
        a.push_back(a1);
    }
    int beg = 0;
    int end = was[a[0]];
    int ans = 0;
    count = vector<int>(200000);
    int maxNow = 0;
    for (int i = 0; i < n;i++) {
        if (i > end) {
            ans += end-beg+1-maxNow;
            beg = i;
            end = i;
            maxNow = 0;
        }
        count[a[i]]++;
        maxNow = max(maxNow, count[a[i]]);
        end = max(end, was[a[i]]);
    }
    ans += end-beg+1-maxNow;
    cout << ans;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> gr [100001];
vector<bool> visit;
int myCount;

void dfs(int i) {
    visit[i] = true;
    myCount++;
    for (int v : gr[i]) {
        if (!visit[v])
            dfs(v);
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a;
    vector<int> was;
    vector<int> count;
    was = vector<int>(200000);
    fill(was.begin(), was.end(), -1);
    for (int i = 0; i < n; i++) {
        int a1;
        cin >> a1;
        was[a1] = i;
        a.push_back(a1);
    }
    int beg = 0;
    int end = was[a[0]];
    int ans = 0;
    count = vector<int>(200000);
    int maxNow = 0;
    for (int i = 0; i < n;i++) {
        if (i > end) {
            ans += end-beg+1-maxNow;
            beg = i;
            end = i;
            count = vector<int>(200000);
            maxNow = 0;
        }
        count[a[i]]++;
        maxNow = max(maxNow, count[a[i]]);
        end = max(end, was[a[i]]);
    }
    ans += end-beg+1-maxNow;
    cout << ans;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> gr [100001];
vector<bool> visit;
int myCount;

void dfs(int i) {
    visit[i] = true;
    myCount++;
    for (int v : gr[i]) {
        if (!visit[v])
            dfs(v);
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a;
    vector<int> was;
    vector<int> count;
    was = vector<int>(200000);
    count = vector<int>(200000);
    fill(was.begin(), was.end(), -1);
    for (int i = 0; i < n; i++) {
        int a1;
        cin >> a1;
        was[a1] = i;
        a.push_back(a1);
    }
    int beg = 0;
    int end = was[a[0]];
    int ans = 0;
    for (int i = 0; i < n;i++) {
        if (i > end) {
            int maxNow = 0;
            fill(count.begin(), count.end(), 0);
            for (int j = beg; j <= end; j++) {
                count[a[j]]++;
                maxNow = max(maxNow, count[a[j]]);
            }
            ans += end-beg+1-maxNow;
            beg = i;
            end = i;
        }
        end = max(end, was[a[i]]);
    }
    int maxNow = 0;
    fill(count.begin(), count.end(), 0);
    for (int j = beg; j <= end; j++) {
        count[a[j]]++;
        maxNow = max(maxNow, count[a[j]]);
    }
    ans += end-beg+1-maxNow;
    cout << ans;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> gr [100001];
vector<bool> visit;
int myCount;

void dfs(int i) {
    visit[i] = true;
    myCount++;
    for (int v : gr[i]) {
        if (!visit[v])
            dfs(v);
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a;
    vector<int> was;
    vector<int> count;
    was = vector<int>(200000);
    fill(was.begin(), was.end(), -1);
    for (int i = 0; i < n; i++) {
        int a1;
        cin >> a1;
        was[a1] = i;
        a.push_back(a1);
    }
    int beg = 0;
    int end = was[a[0]];
    int ans = 0;
    for (int i = 0; i < n;i++) {
        if (i > end) {
            int maxNow = 0;
            count = vector<int>(200000);
            for (int j = beg; j <= end; j++) {
                count[a[j]]++;
                maxNow = max(maxNow, count[a[j]]);
            }
            ans += end-beg+1-maxNow;
            beg = i;
            end = i;
        }
        end = max(end, was[a[i]]);
    }
    int maxNow = 0;
    count = vector<int>(200000);
    fill(count.begin(), count.end(), 0);
    for (int j = beg; j <= end; j++) {
        count[a[j]]++;
        maxNow = max(maxNow, count[a[j]]);
    }
    ans += end-beg+1-maxNow;
    cout << ans;
}


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 200100;
const int INF = 0x3f3f3f3f;

int v[MAXN];
int pai[MAXN];
int last[MAXN],low[MAXN];
int q[MAXN];
int r[MAXN];

int find(int x){
	if(pai[x] == x) return x;
	return pai[x] = find(pai[x]);
}

void join(int a,int b){
	pai[find(a)] = find(b);
}

bool vis[MAXN];

int main(){
	memset(low,INF,sizeof low);
	memset(r,0,sizeof r);
	memset(last,-1,sizeof last);
	memset(q,0,sizeof q);

	int n,t;
	cin >> n >> t;

	for(int i = 1;i <= n;i++) cin >> v[i] , q[v[i]] ++;
	for(int i = n;i >= 1;i--) last[v[i]] = max(last[v[i]] , i);
	for(int i = 1;i <= n;i++) low[v[i]] = min(low[v[i]],i);

	for(int i = 1;i <= 200000;i++) pai[i] = i , r[i] = q[i];

	int resp = 0;

	for(int i = 2;i < n;i++){
		if(last[v[i]] > i){
			join(v[i],v[i + 1]);
			r[find(v[i])] = max(r[v[i]],r[v[i+1]]);
		}
		if(low[v[i]] < i){
			//cout << "/ " << i << endl;
			join(v[i],v[i - 1]);
			r[find(v[i])] = max(r[v[i]],r[v[i-1]]);
		}
	}

	for(int i = 1;i <= n;i++){
		if(vis[find(v[i])] == true) continue;
	//	cout << "a " << v[i] << endl;
		int a = find(v[i]);
		resp += r[a];
		vis[a] = true;
	}

	cout << n - resp << endl;

}


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 200100;
const int INF = 0x3f3f3f3f;

int v[MAXN];
int pai[MAXN];
int last[MAXN],low[MAXN];
int q[MAXN];
int r[MAXN];

int find(int x){
	if(pai[x] == x) return x;
	return pai[x] = find(pai[x]);
}

void join(int a,int b){
	pai[find(a)] = find(b);
}

bool vis[MAXN];

int main(){
	memset(low,INF,sizeof low);
	memset(r,0,sizeof r);
	memset(last,-1,sizeof last);
	memset(q,0,sizeof q);

	int n,t;
	cin >> n >> t;

	for(int i = 1;i <= n;i++) cin >> v[i] , q[v[i]] ++;
	for(int i = n;i >= 1;i--) last[v[i]] = max(last[v[i]] , i);

	for(int i = 1;i <= 200000;i++) pai[i] = i , r[i] = q[i];

	int resp = 0;

	int ult = 0 , uni = -1;
	for(int i = 1;i <= n;i++){
		if(ult < i){
			uni = v[i];
			ult = last[v[i]];
			r[uni] = r[v[i]];
		}
		else ult = max(ult,last[v[i]]) , join(v[i] , uni) , r[find(v[i])] = max(r[find(v[i])] , r[v[i]]);
	}

	for(int i = 1;i <= n;i++){
		if(vis[find(v[i])] == true) continue;6 0
		//cout << "a " << v[i] << endl;
		int a = find(v[i]);
		resp += r[a];
		vis[a] = true;
	}

	cout << n - resp << endl;

}


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 200100;
const int INF = 0x3f3f3f3f;

int v[MAXN];
int pai[MAXN];
int last[MAXN],low[MAXN];
int q[MAXN];
int r[MAXN];

int find(int x){
	if(pai[x] == x) return x;
	return pai[x] = find(pai[x]);
}

void join(int a,int b){
	pai[find(a)] = find(b);
}

bool vis[MAXN];

int main(){
	memset(low,INF,sizeof low);
	memset(r,0,sizeof r);
	memset(last,-1,sizeof last);
	memset(q,0,sizeof q);

	int n,t;
	cin >> n >> t;

	for(int i = 1;i <= n;i++) cin >> v[i] , q[v[i]] ++;
	for(int i = n;i >= 1;i--) last[v[i]] = max(last[v[i]] , i);
	for(int i = 1;i <= n;i++) low[v[i]] = min(low[v[i]],i);

	for(int i = 1;i <= 200000;i++) pai[i] = i , r[i] = q[i];

	int resp = 0;

	for(int i = 1;i <= n;i++){
		if(i < n && last[v[i]] > i){
			r[v[i]] = max(r[find(v[i])],r[find(v[i+1])]);
			join(v[i],v[i + 1]);
			r[find(v[i])] = r[v[i]];
		}
		if(i > 1 && low[v[i]] < i){
			//cout << "/ " << i << endl;
			r[v[i]] = max(r[find(v[i])],r[find(v[i-1])]);
			join(v[i],v[i - 1]);
			r[find(v[i])] = r[v[i]];
		}
	}

	for(int i = 1;i <= n;i++){
		if(vis[find(v[i])] == true) continue;
		//cout << "a " << v[i] << endl;
		int a = find(v[i]);
		resp += r[a];
		vis[a] = true;
	}

	cout << n - resp << endl;

}


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 200100;
const int INF = 0x3f3f3f3f;

int v[MAXN];
int pai[MAXN];
int last[MAXN],low[MAXN];
int q[MAXN];
int r[MAXN];

int find(int x){
	if(pai[x] == x) return x;
	return pai[x] = find(pai[x]);
}

void join(int a,int b){
	pai[find(a)] = find(b);
}

bool vis[MAXN];

int main(){
	memset(low,INF,sizeof low);
	memset(r,0,sizeof r);
	memset(last,-1,sizeof last);
	memset(q,0,sizeof q);

	int n,t;
	cin >> n >> t;

	for(int i = 1;i <= n;i++) cin >> v[i] , q[v[i]] ++;
	for(int i = n;i >= 1;i--) last[v[i]] = max(last[v[i]] , i);
	for(int i = 1;i <= n;i++) low[v[i]] = min(low[v[i]],i);

	for(int i = 1;i <= 200000;i++) pai[i] = i , r[i] = q[i];

	int resp = 0;

	for(int i = 2;i < n;i++){
		if(last[v[i]] > i){
			r[v[i]] = max(r[find(v[i])],r[find(v[i+1])]);
			join(v[i],v[i + 1]);
			r[find(v[i])] = r[v[i]];
		}
		if(low[v[i]] < i){
			//cout << "/ " << i << endl;
			r[v[i]] = max(r[find(v[i])],r[find(v[i-1])]);
			join(v[i],v[i - 1]);
			r[find(v[i])] = r[v[i]];
		}
	}

	for(int i = 1;i <= n;i++){
		if(vis[find(v[i])] == true) continue;
		//cout << "a " << v[i] << endl;
		int a = find(v[i]);
		resp += r[a];
		vis[a] = true;
	}

	cout << n - resp << endl;

}


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 200100;
const int INF = 0x3f3f3f3f;

int v[MAXN];
int pai[MAXN];
int last[MAXN],low[MAXN];
int q[MAXN];
int r[MAXN];

int find(int x){
	if(pai[x] == x) return x;
	return pai[x] = find(pai[x]);
}

void join(int a,int b){
	pai[find(a)] = find(b);
}

bool vis[MAXN];

int main(){
	memset(low,INF,sizeof low);
	memset(r,0,sizeof r);
	memset(last,-1,sizeof last);
	memset(q,0,sizeof q);

	int n,t;
	cin >> n >> t;

	for(int i = 1;i <= n;i++) cin >> v[i] , q[v[i]] ++;
	for(int i = n;i >= 1;i--) last[v[i]] = max(last[v[i]] , i);

	for(int i = 1;i <= 200000;i++) pai[i] = i , r[i] = q[i];

	int resp = 0;

	int ult = 0 , uni = -1;
	for(int i = 1;i <= n;i++){
		if(ult < i){
			uni = v[i];
			ult = last[v[i]];
			r[uni] = r[v[i]];
		}
		else ult = max(ult,last[v[i]]) , join(v[i] , uni) , r[find(v[i])] = max(r[find(v[i])] , r[v[i]]);
	}

	for(int i = 1;i <= n;i++){
		if(vis[find(v[i])] == true) continue;
		//cout << "a " << v[i] << endl;
		int a = find(v[i]);
		resp += r[a];
		vis[a] = true;
	}

	cout << n - resp << endl;

}


#include "bits/stdc++.h"

#pragma optimize("O3")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

#define sync                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define MP make_pair
#define endl '\n'

const ll MOD = 1e9+7;
const ll INF = 1e9 + 7;
const int base = 2e5+1;
const int MAX =1e5+2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 2*1e5+47;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

map<int, vi> pos;

int main()
{
	int n, q;
	cin >> n >> q;
	vi v(n);
	FOR(i,0,n)
	{
	    cin >> v[i];
	    pos[v[i]].pb(i);
	}
	int l = 0, r = -1, mx = 1, res = 0;
	FOR(i,0,n)
	{
	    if(r == i)
        {
            //cout << l <<' '<<r<<' '<<mx<<endl;
            res += (r-l+1) - mx;
            l = i+1;
            mx = 1;
        }
        else
        {
            r = max(r, pos[v[i]].back());
            mx = max(mx, SZ(pos[v[i]]));
        }

	}

	cout << res;
	return 0;
}


#include "bits/stdc++.h"

#pragma optimize("O3")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

#define sync                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define MP make_pair
#define endl '\n'

const ll MOD = 1e9+7;
const ll INF = 1e9 + 7;
const int base = 2e5+1;
const int MAX =1e5+2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 2*1e5+47;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int cnt[MAXN], last[MAXN];

int main()
{
	int n, q;
	cin >> n >> q;
	vi v(n+1,0);
	FOR(i,0,n)
	{
	    cin >> v[i];
	    cnt[v[i]]++;
	    last[v[i]] = i;
	}

	int res = 0;
	FOR(i,0,n)
	{
	    int mx = cnt[v[i]];
	    int r = last[v[i]];
	    int j = i;
	    while(j < r)
        {
            r = max(r, last[v[j]]);
            mx = max(mx, cnt[v[j]]);
            j++;
        }
        res += (j - i + 1 - mx);
        i = j;
	}

	cout << res;
	return 0;
}


#include "bits/stdc++.h"

#pragma optimize("O3")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

#define sync                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define MP make_pair
#define endl '\n'

const ll MOD = 1e9+7;
const ll INF = 1e9 + 7;
const int base = 2e5+1;
const int MAX =1e5+2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 2*1e5+47;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int cnt[MAXN], last[MAXN];

int main()
{
	int n, q;
	cin >> n >> q;
	vi v(n+1,0);
	FOR(i,0,n)
	{
	    cin >> v[i];
	    cnt[v[i]]++;
	    last[v[i]] = i;
	}

	int res = 0;
	FOR(i,0,n)
	{
	    int mx = cnt[v[i]];
	    int r = last[v[i]];
	    int j = i;
	    while(j < r)
        {
            r = max(r, last[v[j]]);
            mx = max(mx, cnt[v[j]]);
            j++;
        }
        res += j - i + 1 - mx;
        i = j+1;
	}

	cout << res;
	return 0;
}


#include "bits/stdc++.h"

#pragma optimize("O3")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

#define sync                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define MP make_pair
#define endl '\n'

const ll MOD = 1e9+7;
const ll INF = 1e9 + 7;
const int base = 2e5+1;
const int MAX =1e5+2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 2*1e5+47;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int cnt[MAXN], last[MAXN];

int main()
{
	int n, q;
	cin >> n >> q;
	vi v(n+1,0);
	FOR(i,0,n)
	{
	    cin >> v[i];
	    cnt[v[i]]++;
	    last[v[i]] = i;
	}

	int l = 0, r = -1, mx = 0, res = 0, was = 0;
	FOR(i,0,n)
	{
	    if(r == i)
        {
            //cout << l <<' '<<r<<' '<<mx<<endl;
            res += (r-l+1) - mx;
            l = i+1;
            mx = cnt[v[i]];
            was++;
        }
        else
        {
            r = max(r, last[v[i]]);
            mx = max(mx, cnt[v[i]]);
        }

	}

	cout << res - (was==1);
	return 0;
}


#include "bits/stdc++.h"

#pragma optimize("O3")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

#define sync                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define MP make_pair
#define endl '\n'

const ll MOD = 1e9+7;
const ll INF = 1e9 + 7;
const int base = 2e5+1;
const int MAX =1e5+2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 2*1e5+47;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

map<int, vi> pos;

int main()
{
	int n, q;
	cin >> n >> q;
	vi v(n);
	FOR(i,0,n)
	{
	    cin >> v[i];
	    pos[v[i]].pb(i);
	}
	int l = 0, r = -1, mx = 1, res = 0;
	FOR(i,0,n)
	{
	    if(r == i)
        {
            //cout << l <<' '<<r<<' '<<mx<<endl;
            res += (r-l+1) - mx;
            l = i+1;
            mx = 1;
        }
        r = max(r, pos[v[i]].back());
        mx = max(mx, SZ(pos[v[i]]));
	}

	cout << res;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)2e5 + 10;
// const int mod = (int)1e9 + 7;

vector<int> cnt(MX), lst(MX);

int main(){

    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(0);

    int n, q;
    cin >> n >> q;

    assert(q == 0);

    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        cnt[a[i]]++;
        lst[a[i]] = i;
    }

    int L = 0, R = 0, res = 0, mx = 0;
    for(int i = 0; i < n; ++i){

        R = max(R, lst[a[i]]);
        mx = max(mx, cnt[a[i]]);

        if(i == R){
            res += R - L + 1 - mx;
            mx = 0;
            L = R = i + 1;
        }
    }

    cout << res << endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)2e5 + 10;
// const int mod = (int)1e9 + 7;

vector<int> cnt(MX), lst(MX);

int main(){

    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(0);

    int n, q;
    cin >> n >> q;

    assert(q == 0);

    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        cnt[a[i]]++;
        lst[a[i]] = i;
    }

    int L = 0, R = 0, res = 0, mx = 0;
    for(int i = 0; i < n; ++i){

        R = max(R, lst[a[i]]);
        mx = max(mx, cnt[a[i]]);

        if(i == R){
            res += R - L + 1 - mx;
            L = R = i + 1;
        }
    }

    cout << res << endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e5 + 10;
// const int mod = (int)1e9 + 7;

vector<int> cnt(MX), lst(MX);

int main(){

    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(0);

    int n, q;
    cin >> n >> q;

    assert(q == 0);

    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        cnt[a[i]]++;
        lst[a[i]] = i;
    }

    int L = 0, R = 0, res = 0, mx = 0;
    for(int i = 0; i < n; ++i){

        R = max(R, lst[a[i]]);
        mx = max(mx, cnt[a[i]]);

        if(i == R){
            res += R - L + 1 - mx;
            L = R = i + 1;
        }
    }

    cout << res << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int K = 200000;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, Q;
    cin >> N >> Q;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i]; A[i]--;
    }

    vector<int> start(K, N); // index of first occ
    vector<int> finish(K, -1); // index of last occ

    vector<int> recol(K);
    iota(recol.begin(), recol.end(),0);

    for(int i=0;i<N;i++){
        start[A[i]] = min(start[A[i]], i);
        finish[A[i]] = max(finish[A[i]], i);
    }

    // for(int i=0;i<200000;i++){
    //     if(start[i] != N)
    //         cout << i << ":\t" << start[i] << " " << finish[i] << endl;
    // }
    vector<pair<int,int>> interval;
    int i=0;
    int s;
    int f;
    while(i != N){
        s = i;
        f = finish[A[i]];
        //cout << "START" << i << endl;
        // int c = recol[A[i]];

        while(i != f){
            f = max(f, finish[A[i]]);
            i++;
        }
        //cout << "END" << i << endl;
        interval.push_back({s, i});

        i++;
    }

    int diff = 0;
    for(auto [a,b] : interval){
        // find most common in this interval
        map<int,int> count;
        for(int i=a;i<=b;i++)
            count[A[i]]++;
        int max = 0;
        for(auto [k,v] : count)
            max = std::max(max, v);
        diff = (b-a+1) - max;
    }
    cout << diff << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int K = 200000;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, Q;
    cin >> N >> Q;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i]; A[i]--;
    }

    vector<int> start(K, N); // index of first occ
    vector<int> finish(K, -1); // index of last occ

    vector<int> recol(K);
    iota(recol.begin(), recol.end(),0);

    for(int i=0;i<N;i++){
        start[A[i]] = min(start[A[i]], i);
        finish[A[i]] = max(finish[A[i]], i);
    }

    // for(int i=0;i<200000;i++){
    //     if(start[i] != N)
    //         cout << i << ":\t" << start[i] << " " << finish[i] << endl;
    // }
    vector<pair<int,int>> interval;
    int i=0;
    int s;
    int f;
    while(i != N){
        s = i;
        f = finish[A[i]];
        //cout << "START" << i << endl;
        // int c = recol[A[i]];

        while(i != f){
            f = max(f, finish[A[i]]);
            i++;
        }
        //cout << "END" << i << endl;
        interval.push_back({s, i});

        i++;
    }

    int diff = 0;
    for(auto [a,b] : interval){
        // find most common in this interval
        map<int,int> count;
        for(int i=a;i<=b;i++){
            if(count.count(A[i]) == 0) count[A[i]] = 0;
            count[A[i]]++;
        }
        int max = 0;
        for(auto [k,v] : count)
            max = std::max(max, v);
        diff += (b-a+1) - max;
    }
    cout << diff << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int K = 200000;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, Q;
    cin >> N >> Q;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i]; A[i]--;
    }

    vector<int> start(K, N); // index of first occ
    vector<int> finish(K, -1); // index of last occ

    vector<int> recol(K);
    iota(recol.begin(), recol.end(),0);

    for(int i=0;i<N;i++){
        start[A[i]] = min(start[A[i]], i);
        finish[A[i]] = max(finish[A[i]], i);
    }

    // for(int i=0;i<200000;i++){
    //     if(start[i] != N)
    //         cout << i << ":\t" << start[i] << " " << finish[i] << endl;
    // }
    vector<pair<int,int>> interval;
    int i=0;
    int s;
    int f;
    while(i != N){
        s = i;
        f = finish[A[i]];
        //cout << "START" << i << endl;
        // int c = recol[A[i]];

        while(i != f){
            f = max(f, finish[A[i]]);
            i++;
        }
        //cout << "END" << i << endl;
        interval.push_back({s, i});

        i++;
    }

    int diff = 0;
    for(auto [a,b] : interval){
        // find most common in this interval
        map<int,int> count;
        for(int i=a;i<=b;i++){
            if(count.count(A[i]) == 0) count[A[i]] = 0;
            count[A[i]]++;
        }
        int max = 0;
        for(auto [k,v] : count)
            max = std::max(max, v);
        diff = (b-a+1) - max;
    }
    cout << diff << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, Q;
    cin >> N >> Q;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i]; A[i]--;
    }

    vector<int> start(200000, N); // index of first occ
    vector<int> finish(200000, -1); // index of last occ

    vector<int> recol(200000);
    iota(recol.begin(), recol.end(),0);

    for(int i=0;i<N;i++){
        start[A[i]] = min(start[A[i]], i);
        finish[A[i]] = max(finish[A[i]], i);
    }

    // for(int i=0;i<200000;i++){
    //     if(start[i] != N)
    //         cout << i << ":\t" << start[i] << " " << finish[i] << endl;
    // }
    vector<pair<int,int>> interval;
    int i=0;
    int s;
    while(i != N){
        s = i;
        //cout << "START" << i << endl;
        int c = recol[A[i]];

        while(i != finish[c]){
            // look at current value and merge in
            if(recol[A[i]] != c){
                int prev = recol[A[i]];
                finish[c] = max(finish[c], finish[prev]);
                recol[A[i]] = c;
            }
            i++;
        }
        //cout << "END" << i << endl;
        interval.push_back({s, i});

        i++;
    }

    int diff = 0;
    for(auto [a,b] : interval){
        // find most common in this interval
        map<int,int> count;
        for(int i=a;i<=b;i++)
            count[A[i]]++;
        int max = 0;
        for(auto [k,v] : count)
            max = std::max(max, v);
        diff = (b-a+1) - max;
    }
    cout << diff << endl;

    return 0;
}


#include <iostream>
#include <map>
#include <vector>

using namespace std;

struct x {
    int start;
    int finish;
    int cnt;
    int value;
};

int main() {
    int n, q, y, j = 1;
    cin >> n >> q;
    vector < x > ar;
    map <int, int> pos;
    ar.push_back(x{-1, -1, -1, -1});
    for (int i = 0; i < n; i++) {
        cin >> y;
        q = pos[y];
        if (pos[y] == 0){
            pos[y] = j;
            j++;
            ar.push_back(x{i, i, 1, y});
        } else {
            ar[pos[y]].finish = i;
            ar[pos[y]].cnt++;
        }
    }
    int s = ar.size(), ans = 0;
    vector < x > scan;
    for (int i = 1; i < s; i++) {
        if (!scan.empty()) {
            if (scan[0].finish < ar[i].start) {
                scan.clear();
            }
        }
        if (scan.empty()) {
            scan.push_back(ar[i]);
        } else {
            if (ar[i].cnt > scan[0].cnt) {
                scan[0].value = ar[i].value;
            }
            ans += min(scan[0].cnt, ar[i].cnt);
            scan[0].cnt += ar[i].cnt;
            scan[0].finish = max(scan[0].finish, ar[i].finish);
            scan[0].start = min(scan[0].start, ar[i].start);
        }
    }
    cout << ans;
}


#include <iostream>
#include <map>
#include <vector>

using namespace std;

struct x {
    int start;
    int finish;
    int cnt;
    int value;
};

int main() {
    int n, q, y, j = 1;
    cin >> n >> q;
    vector < x > ar;
    map <int, int> pos;
    ar.push_back(x{-1, -1, -1, -1});
    for (int i = 0; i < n; i++) {
        cin >> y;
        q = pos[y];
        if (pos[y] == 0){
            pos[y] = j;
            j++;
            ar.push_back(x{i, i, 1, y});
        } else {
            ar[pos[y]].finish = i;
            ar[pos[y]].cnt++;
        }
    }
    int s = ar.size(), ans = 0, check = 0, first;
    vector < x > scan;
    for (int i = 1; i < s; i++) {
        if (!scan.empty()) {
            if (scan[0].finish < ar[i].start) {
                scan.clear();
                ans = ans - check + first;
            }
        }
        if (scan.empty()) {
            scan.push_back(ar[i]);
            first = ar[i].cnt;
            check = ar[i].cnt;
        } else {
            if (ar[i].cnt > scan[0].cnt) {
                scan[0].value = ar[i].value;
            }
            if ((check < ar[i].cnt) && (ar[i].cnt < scan[0].cnt)) {
                check = ar[i].cnt;
            } else if (check < ar[i].cnt){
                first = ar[i].cnt;
                check = ar[i].cnt;
            }
            ans += min(scan[0].cnt, ar[i].cnt);
            scan[0].cnt += ar[i].cnt;
            scan[0].finish = max(scan[0].finish, ar[i].finish);
            scan[0].start = min(scan[0].start, ar[i].start);
        }
    }
    ans = ans - check + first;
    cout << ans;
}


#include <iostream>
#include <map>
#include <vector>

using namespace std;

struct x {
    int start;
    int finish;
    int cnt;
    int value;
};

int main() {
    int n, q, y, j = 1;
    cin >> n >> q;
    vector < x > ar;
    map <int, int> pos;
    ar.push_back(x{-1, -1, -1, -1});
    for (int i = 0; i < n; i++) {
        cin >> y;
        q = pos[y];
        if (pos[y] == 0){
            pos[y] = j;
            j++;
            ar.push_back(x{i, i, 1, y});
        } else {
            ar[pos[y]].finish = i;
            ar[pos[y]].cnt++;
        }
    }
    int s = ar.size(), ans = 0, check;
    vector < x > scan;
    for (int i = 1; i < s; i++) {
        if (!scan.empty()) {
            if (scan[0].finish < ar[i].start) {
                scan.clear();
            }
        }
        if (scan.empty()) {
            scan.push_back(ar[i]);
            check = ar[i].cnt;
        } else {
            if (ar[i].cnt > scan[0].cnt) {
                scan[0].value = ar[i].value;
            }
            if ((check < ar[i].cnt) && (ar[i].cnt < scan[0].cnt)) {
                ans -= ar[i].cnt;
                ans += check;
            } else if (check < ar[i].cnt) {
                check = ar[i].cnt;
            }
            ans += min(scan[0].cnt, ar[i].cnt);
            scan[0].cnt += ar[i].cnt;
            scan[0].finish = max(scan[0].finish, ar[i].finish);
            scan[0].start = min(scan[0].start, ar[i].start);
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int ull;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

ll gcd(ll a,ll b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

const int N=400010,M=1<<19,B=600;
//const int N=15,M=1<<4,B=5;
int n,q,h[N],ans,ma[N],mi[N],poss[N],s[N/B+10][N/B+10],s1[N/B+10][N/B+10],pr[N];
vi pos[N];
pii seg[M*4+10]; //min, posMin
int prop[M*4+10];
set<int> ens;

bool isFreqOfBeg(int i,int j,int x)
{
	int a=poss[i]+x-1;
	if (pos[h[i]].size()>a && pos[h[i]][a]<=j) return 1;
	return 0;
}

bool isFreqOfEnd(int i,int j,int x)
{
	int a=poss[j]-x+1;
	if (pos[h[j]].size()>a && pos[h[j]][a]>=i) return 1;
	return 0;
}

void pro(int i)
{
	seg[i].x+=prop[i];
	prop[i*2]+=prop[i];
	prop[i*2+1]+=prop[i];
	prop[i]=0;
}

void upd(int l,int r,int x,int lo=0,int hi=M,int i=1)
{
	pro(i);
	if (lo>=l && hi<=r)
	{
		prop[i]+=x;
		pro(i);
		return;
	}
	if (lo>=r || hi<=l) return;
	int mid=(lo+hi)/2;
	upd(l,r,x,lo,mid,i*2);
	upd(l,r,x,mid,hi,i*2+1);
	seg[i]=min(seg[i*2],seg[i*2+1]);
}

pii get(int l,int r,int lo=0,int hi=M,int i=1)
{
	pro(i);
	if (lo>=l && hi<=r) return seg[i];
	if (lo>=r || hi<=l) return {MOD,-MOD};
	int mid=(lo+hi)/2;
	return min(get(l,r,lo,mid,i*2),get(l,r,mid,hi,i*2+1));
}

int maxAp(int i,int j)
{
	int _i=(i+B-1)/B,_j=j/B;
	int ans=s1[_i][_j];
	//cout<<_i<<' '<<_j<<en;
	for (int a=i;a<min(_i*B,j+1);++a)
	{
		while (isFreqOfBeg(a,j,ans+1)) ++ans;
	}
	for (int a=_j*B;a<=j;++a)
	{
		while (isFreqOfEnd(i,a,ans+1)) ++ans;
	}
	return ans;
}

int maxAp2(int i,int j)
{
	multiset<int> m;
	for (int k=i;k<=j;k+=2) m.insert(h[k]);
	int ma=0;
	for (int k=i;k<=j;k+=2) ma=max(ma,m.count(h[k]));
	return ma;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829)+13893829);
	cin>>n>>q;
	n*=2;
	for (int i=M+n;i<M+M;++i) seg[i].x=MOD,seg[i].y=-MOD;
	for (int i=M-1;i>0;--i) seg[i]=min(seg[i*2],seg[i*2+1]);
	memset(mi,63,sizeof(mi));
	memset(ma,-1,sizeof(ma));
	for (int i=0;i<n;++i) seg[i+M].y=i;
	for (int i=0;i<n;i+=2)
	{
		cin>>h[i];
		poss[i]=pos[h[i]].size();
		pos[h[i]].pb(i);
		mi[h[i]]=min(mi[h[i]],i);
		ma[h[i]]=max(ma[h[i]],i);
	}
	for (int i=0;i<n;i+=B)
	{
		int ma1=0,ma2=0;
		for (int j=i;j<n;++j)
		{
			if (j>i && j%B==0) s[i/B][j/B]=ma1,s1[i/B][j/B]=ma2;
			while (isFreqOfEnd(i,j,ma2+1)) ++ma2,ma1=h[j];
		}
	}
	/*for (int i=0;i<n;i+=2) for (int j=i;j<n;j+=2) if (maxAp(i,j)!=maxAp2(i,j))
	{
		cout<<i/2<<' '<<j/2<<' '<<maxAp(i,j)<<' '<<maxAp2(i,j)<<en;
	}*/
	ens.insert(0);
	for (int i=0;i<=N/2;++i) if (ma[i]!=-1)
	{
		++pr[mi[i]];
		--pr[ma[i]+1];
		upd(mi[i],ma[i]+1,1);
	}
	for (int i=1;i<n;++i) pr[i]+=pr[i-1];
	int la=0;
	while (1)
	{
		auto res=get(la,n-1);
		if (res.x)
		{
			ens.insert(n);
			break;
		}
		else
		{
			la=res.y+1;
			ens.insert(la);
		}
	}
	//for (int i=0;i<n;++i) if (pr[i]==0) ens.insert(i);
	vi u;
	for (auto a: ens) u.pb(a);
	ans=n/2;
	for (int i=1;i<u.size();++i)
	{
		//cout<<u[i-1]<<' '<<u[i]<<en;
		ans-=maxAp(u[i-1],u[i]);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int ull;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

ll gcd(ll a,ll b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

const int N=400010,M=1<<19,B=600;
//const int N=31,M=1<<5,B=5;
int n,q,h[N],ans,ma[N],mi[N],poss[N],s[B+10][B+10],s1[B+10][B+10],pr[N];
vi pos[N];
pii seg[M*4+10]; //min, posMin
int prop[M*4+10];
set<int> ens;

bool isFreqOfBeg(int i,int j,int x)
{
	int a=poss[i]+x-1;
	if (pos[h[i]].size()>a && pos[h[i]][a]<=j) return 1;
	return 0;
}

bool isFreqOfEnd(int i,int j,int x)
{
	int a=poss[j]-x+1;
	if (pos[h[j]].size()>a && pos[h[j]][a]>=i) return 1;
	return 0;
}

void pro(int i)
{
	seg[i].x+=prop[i];
	prop[i*2]+=prop[i];
	prop[i*2+1]+=prop[i];
	prop[i]=0;
}

void upd(int l,int r,int x,int lo=0,int hi=M,int i=1)
{
	pro(i);
	if (lo>=l && hi<=r)
	{
		prop[i]+=x;
		pro(i);
		return;
	}
	if (lo>=r || hi<=l) return;
	int mid=(lo+hi)/2;
	upd(l,r,x,lo,mid,i*2);
	upd(l,r,x,mid,hi,i*2+1);
	seg[i]=min(seg[i*2],seg[i*2+1]);
}

pii get(int l,int r,int lo=0,int hi=M,int i=1)
{
	pro(i);
	if (lo>=l && hi<=r) return seg[i];
	if (lo>=r || hi<=l) return {MOD,-MOD};
	int mid=(lo+hi)/2;
	return min(get(l,r,lo,mid,i*2),get(l,r,mid,hi,i*2+1));
}

int maxAp(int i,int j)
{
	int _i=(i+B-1)/B,_j=j/B;
	int ans=s1[_i][_j];
	//cout<<_i<<' '<<_j<<en;
	for (int a=i;a<min(_i*B,j+1);++a)
	{
		while (isFreqOfBeg(a,j,ans+1)) ++ans;
	}
	for (int a=_j*B;a<=j;++a)
	{
		while (isFreqOfEnd(i,a,ans+1)) ++ans;
	}
	return ans;
}

int maxAp2(int i,int j)
{
	multiset<int> m;
	for (int k=i;k<=j;k+=2) m.insert(h[k]);
	int ma=0;
	for (int k=i;k<=j;k+=2) ma=max(ma,m.count(h[k]));
	return ma;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829)+13893829);
	cin>>n>>q;
	n*=2;
	for (int i=M+n;i<M+M;++i) seg[i].x=MOD,seg[i].y=-MOD;
	for (int i=M-1;i>0;--i) seg[i]=min(seg[i*2],seg[i*2+1]);
	memset(mi,63,sizeof(mi));
	memset(ma,-1,sizeof(ma));
	for (int i=0;i<n;++i) seg[i+M].y=i;
	for (int i=0;i<n;i+=2)
	{
		cin>>h[i];
		poss[i]=pos[h[i]].size();
		pos[h[i]].pb(i);
		mi[h[i]]=min(mi[h[i]],i);
		ma[h[i]]=max(ma[h[i]],i);
	}
	for (int i=0;i<n;i+=B)
	{
		int ma1=0,ma2=0;
		for (int j=i;j<n;++j)
		{
			if (j>i && j%B==0) s[i/B][j/B]=ma1,s1[i/B][j/B]=ma2;
			while (isFreqOfEnd(i,j,ma2+1)) ++ma2,ma1=h[j];
		}
	}
	/*for (int i=0;i<n;i+=2) for (int j=i;j<n;j+=2) if (maxAp(i,j)!=maxAp2(i,j))
	{
		cout<<i/2<<' '<<j/2<<' '<<maxAp(i,j)<<' '<<maxAp2(i,j)<<en;
	}*/
	ens.insert(0);
	for (int i=0;i<=N/2;++i) if (ma[i]!=-1)
	{
		++pr[mi[i]];
		--pr[ma[i]+1];
		upd(mi[i],ma[i]+1,1);
	}
	for (int i=1;i<n;++i) pr[i]+=pr[i-1];
	int la=0;
	while (1)
	{
		auto res=get(la,n-1);
		if (res.x)
		{
			ens.insert(n);
			break;
		}
		else
		{
			la=res.y+1;
			ens.insert(la);
		}
	}
	//for (int i=0;i<n;++i) if (pr[i]==0) ens.insert(i);
	vi u;
	for (auto a: ens) u.pb(a);
	ans=n/2;
	for (int i=1;i<u.size();++i)
	{
		//cout<<u[i-1]<<' '<<u[i]<<en;
		ans-=maxAp(u[i-1],u[i]);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int ull;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

ll gcd(ll a,ll b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

const int N=300010;
int t,n,q,par[N],ma[N],sz[N];
vi di[N];

int find(int i)
{
	if (i==par[i]) return i;
	return par[i]=find(par[i]);
}

void merge(int a,int b)
{
	a=find(a);
	b=find(b);
	if (a!=b)
	{
		if (sz[a]>sz[b]) swap(a,b);
		par[a]=b;
		ma[b]=max(ma[a],ma[b]);
		sz[b]+=sz[a];
	}
}

int solve(int n,vector<pii> ed)
{
	for (int i=1;i<=n;++i) par[i]=i,ma[i]=i,sz[i]=1;
	for (auto e: ed)
	{
		merge(e.x,e.y);
	}
	int ans=0;
	for (int i=1;i<n;i++) if (find(i)!=find(i+1) && ma[find(i)]!=i)
	{
		ans+=min(sz[find(i)],sz[find(i+1)]);
		merge(i,i+1);
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829)+13893829);
	cin>>n>>q;
	for (int i=1;i<=n;++i)
	{
		int a;
		cin>>a;
		di[a].pb(i);
	}
	vector<pii> ed;
	for (int i=0;i<=200000;++i)
	{
		for (int j=1;j<di[i].size();++j) ed.pb({di[i][j],di[i][j-1]});
	}
	cout<<solve(n,ed);
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int ull;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

ll gcd(ll a,ll b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

//const int N=400010,M=1<<19,B=600;
const int N=31,M=1<<5,B=5;
int n,q,h[N],ans,ma[N],mi[N],poss[N],s[B+10][B+10],s1[B+10][B+10];
vi pos[N];
pii seg[M*4+10]; //min, posMin
int prop[M*4+10];
set<int> ens;

bool isFreqOfBeg(int i,int j,int x)
{
	int a=poss[i]+x-1;
	if (pos[h[i]].size()>a && pos[h[i]][a]<=j) return 1;
	return 0;
}

bool isFreqOfEnd(int i,int j,int x)
{
	int a=poss[j]-x+1;
	if (pos[h[j]].size()>a && pos[h[j]][a]>=i) return 1;
	return 0;
}

void pro(int i)
{
	seg[i].x+=prop[i];
	prop[i*2]+=prop[i];
	prop[i*2+1]+=prop[i];
	prop[i]=0;
}

void upd(int l,int r,int x,int lo=0,int hi=M,int i=1)
{
	pro(i);
	if (lo>=l && hi<=r)
	{
		prop[i]+=x;
		pro(i);
		return;
	}
	if (lo>=r || hi<=l) return;
	int mid=(lo+hi)/2;
	upd(l,r,x,lo,mid,i*2);
	upd(l,r,x,mid,hi,i*2+1);
	seg[i]=min(seg[i*2],seg[i*2+1]);
}

pii get(int l,int r,int lo=0,int hi=M,int i=1)
{
	pro(i);
	if (lo>=l && hi<=r) return seg[i];
	if (lo>=r || hi<=l) return {MOD,-MOD};
	int mid=(lo+hi)/2;
	return min(get(l,r,lo,mid,i*2),get(l,r,mid,hi,i*2+1));
}

int maxAp(int i,int j)
{
	int _i=(i+B-1)/B,_j=j/B;
	int ans=s1[_i][_j];
	for (int a=i;a<min(_i*B,j+1);++a)
	{
		while (isFreqOfBeg(a,j,ans+1)) ++ans;
	}
	for (int a=_j*B;a<=j;++a)
	{
		while (isFreqOfBeg(i,a,ans+1)) ++ans;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829)+13893829);
	cin>>n>>q;
	n*=2;
	for (int i=M+n;i<M+M;++i) seg[i].x=MOD,seg[i].y=-MOD;
	for (int i=M-1;i>0;--i) seg[i]=min(seg[i*2],seg[i*2+1]);
	memset(mi,63,sizeof(mi));
	memset(ma,-1,sizeof(ma));
	for (int i=0;i<n;++i) seg[i+M].y=i;
	for (int i=0;i<n;i+=2)
	{
		cin>>h[i];
		poss[i]=pos[h[i]].size();
		pos[h[i]].pb(i);
		mi[h[i]]=min(mi[h[i]],i);
		ma[h[i]]=max(ma[h[i]],i);
	}
	for (int i=0;i<n;i+=B)
	{
		int ma1=0,ma2=0;
		for (int j=i;j<n;++j)
		{
			if (j>i && j%B==0) s[i/B][j/B]=ma1,s1[i/B][j/B]=ma2;
			while (isFreqOfEnd(i,j,ma2+1)) ++ma2,ma1=h[j];
		}
	}
	ens.insert(0);
	for (int i=0;i<=N/2;++i) if (ma[i]!=-1)
	{
		upd(mi[i],ma[i]+1,1);
	}
	int la=0;
	while (1)
	{
		auto res=get(la,n-1);
		if (res.x)
		{
			ens.insert(n);
			break;
		}
		else
		{
			la=res.y+1;
			ens.insert(la);
		}
	}
	vi u;
	for (auto a: ens) u.pb(a);
	ans=n/2;
	for (int i=1;i<u.size();++i)
	{
		//cout<<u[i-1]<<' '<<u[i]<<en;
		ans-=maxAp(u[i-1],u[i]);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int ull;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

ll gcd(ll a,ll b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

const int N=400010,M=1<<19,B=600;
//const int N=31,M=1<<5,B=5;
int n,q,h[N],ans,ma[N],mi[N],poss[N],s[B+10][B+10],s1[B+10][B+10],pr[N];
vi pos[N];
pii seg[M*4+10]; //min, posMin
int prop[M*4+10];
set<int> ens;

bool isFreqOfBeg(int i,int j,int x)
{
	int a=poss[i]+x-1;
	if (pos[h[i]].size()>a && pos[h[i]][a]<=j) return 1;
	return 0;
}

bool isFreqOfEnd(int i,int j,int x)
{
	int a=poss[j]-x+1;
	if (pos[h[j]].size()>a && pos[h[j]][a]>=i) return 1;
	return 0;
}

void pro(int i)
{
	seg[i].x+=prop[i];
	prop[i*2]+=prop[i];
	prop[i*2+1]+=prop[i];
	prop[i]=0;
}

void upd(int l,int r,int x,int lo=0,int hi=M,int i=1)
{
	pro(i);
	if (lo>=l && hi<=r)
	{
		prop[i]+=x;
		pro(i);
		return;
	}
	if (lo>=r || hi<=l) return;
	int mid=(lo+hi)/2;
	upd(l,r,x,lo,mid,i*2);
	upd(l,r,x,mid,hi,i*2+1);
	seg[i]=min(seg[i*2],seg[i*2+1]);
}

pii get(int l,int r,int lo=0,int hi=M,int i=1)
{
	pro(i);
	if (lo>=l && hi<=r) return seg[i];
	if (lo>=r || hi<=l) return {MOD,-MOD};
	int mid=(lo+hi)/2;
	return min(get(l,r,lo,mid,i*2),get(l,r,mid,hi,i*2+1));
}

int maxAp(int i,int j)
{
	int _i=(i+B-1)/B,_j=j/B;
	int ans=s1[_i][_j];
	for (int a=i;a<min(_i*B,j+1);++a)
	{
		while (isFreqOfBeg(a,j,ans+1)) ++ans;
	}
	for (int a=_j*B;a<=j;++a)
	{
		while (isFreqOfBeg(i,a,ans+1)) ++ans;
	}
	return ans;
}

int maxAp2(int i,int j)
{
	multiset<int> m;
	for (int k=i;k<=j;k+=2) m.insert(h[k]);
	int ma=0;
	for (int k=i;k<=j;k+=2) ma=max(ma,m.count(h[k]));
	return ma;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829)+13893829);
	cin>>n>>q;
	n*=2;
	for (int i=M+n;i<M+M;++i) seg[i].x=MOD,seg[i].y=-MOD;
	for (int i=M-1;i>0;--i) seg[i]=min(seg[i*2],seg[i*2+1]);
	memset(mi,63,sizeof(mi));
	memset(ma,-1,sizeof(ma));
	for (int i=0;i<n;++i) seg[i+M].y=i;
	for (int i=0;i<n;i+=2)
	{
		cin>>h[i];
		poss[i]=pos[h[i]].size();
		pos[h[i]].pb(i);
		mi[h[i]]=min(mi[h[i]],i);
		ma[h[i]]=max(ma[h[i]],i);
	}
	for (int i=0;i<n;i+=B)
	{
		int ma1=0,ma2=0;
		for (int j=i;j<n;++j)
		{
			if (j>i && j%B==0) s[i/B][j/B]=ma1,s1[i/B][j/B]=ma2;
			while (isFreqOfEnd(i,j,ma2+1)) ++ma2,ma1=h[j];
		}
	}
	for (int i=0;i<n;i+=2) for (int j=i;j<n;j+=2) if (maxAp(i,j)!=maxAp2(i,j))
	{
		cout<<i/2<<' '<<j/2<<' '<<maxAp(i,j)<<' '<<maxAp2(i,j)<<en;
		assert(0);
	}
	ens.insert(0);
	for (int i=0;i<=N/2;++i) if (ma[i]!=-1)
	{
		++pr[mi[i]];
		--pr[ma[i]+1];
		upd(mi[i],ma[i]+1,1);
	}
	for (int i=1;i<n;++i) pr[i]+=pr[i-1];
	/*int la=0;
	while (1)
	{
		auto res=get(la,n-1);
		if (res.x)
		{
			ens.insert(n);
			break;
		}
		else
		{
			la=res.y+1;
			ens.insert(la);
		}
	}*/
	for (int i=0;i<n;++i) if (pr[i]==0) ens.insert(i);
	vi u;
	for (auto a: ens) u.pb(a);
	ans=n/2;
	for (int i=1;i<u.size();++i)
	{
		//cout<<u[i-1]<<' '<<u[i]<<en;
		ans-=maxAp(u[i-1],u[i]);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int ull;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

ll gcd(ll a,ll b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

const int N=400010,M=1<<19,B=600;
//const int N=31,M=1<<5,B=5;
int n,q,h[N],ans,ma[N],mi[N],poss[N],s[B+10][B+10],s1[B+10][B+10];
vi pos[N];
pii seg[M*4+10]; //min, posMin
int prop[M*4+10];
set<int> ens;

bool isFreqOfBeg(int i,int j,int x)
{
	int a=poss[i]+x-1;
	if (pos[h[i]].size()>a && pos[h[i]][a]<=j) return 1;
	return 0;
}

bool isFreqOfEnd(int i,int j,int x)
{
	int a=poss[j]-x+1;
	if (pos[h[j]].size()>a && pos[h[j]][a]>=i) return 1;
	return 0;
}

void pro(int i)
{
	seg[i].x+=prop[i];
	prop[i*2]+=prop[i];
	prop[i*2+1]+=prop[i];
	prop[i]=0;
}

void upd(int l,int r,int x,int lo=0,int hi=M,int i=1)
{
	pro(i);
	if (lo>=l && hi<=r)
	{
		prop[i]+=x;
		pro(i);
		return;
	}
	if (lo>=r || hi<=l) return;
	int mid=(lo+hi)/2;
	upd(l,r,x,lo,mid,i*2);
	upd(l,r,x,mid,hi,i*2+1);
	seg[i]=min(seg[i*2],seg[i*2+1]);
}

pii get(int l,int r,int lo=0,int hi=M,int i=1)
{
	pro(i);
	if (lo>=l && hi<=r) return seg[i];
	if (lo>=r || hi<=l) return {MOD,-MOD};
	int mid=(lo+hi)/2;
	return min(get(l,r,lo,mid,i*2),get(l,r,mid,hi,i*2+1));
}

int maxAp(int i,int j)
{
	int _i=(i+B-1)/B,_j=j/B;
	int ans=s1[_i][_j];
	for (int a=i;a<min(_i*B,j+1);++a)
	{
		while (isFreqOfBeg(a,j,ans+1)) ++ans;
	}
	for (int a=_j*B;a<=j;++a)
	{
		while (isFreqOfBeg(i,a,ans+1)) ++ans;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829)+13893829);
	cin>>n>>q;
	n*=2;
	for (int i=M+n;i<M+M;++i) seg[i].x=MOD,seg[i].y=-MOD;
	for (int i=M-1;i>0;--i) seg[i]=min(seg[i*2],seg[i*2+1]);
	memset(mi,63,sizeof(mi));
	memset(ma,-1,sizeof(ma));
	for (int i=0;i<n;++i) seg[i+M].y=i;
	for (int i=0;i<n;i+=2)
	{
		cin>>h[i];
		poss[i]=pos[h[i]].size();
		pos[h[i]].pb(i);
		mi[h[i]]=min(mi[h[i]],i);
		ma[h[i]]=max(ma[h[i]],i);
	}
	for (int i=0;i<n;i+=B)
	{
		int ma1=0,ma2=0;
		for (int j=i;j<n;++j)
		{
			if (j>i && j%B==0) s[i/B][j/B]=ma1,s1[i/B][j/B]=ma2;
			while (isFreqOfEnd(i,j,ma2+1)) ++ma2,ma1=h[j];
		}
	}
	ens.insert(0);
	for (int i=0;i<=N/2;++i) if (ma[i]!=-1)
	{
		upd(mi[i],ma[i]+1,1);
	}
	int la=0;
	while (1)
	{
		auto res=get(la,n-1);
		if (res.x)
		{
			ens.insert(n);
			break;
		}
		else
		{
			la=res.y+1;
			ens.insert(la);
		}
	}
	vi u;
	for (auto a: ens) u.pb(a);
	ans=n/2;
	for (int i=1;i<u.size();++i)
	{
		//cout<<u[i-1]<<' '<<u[i]<<en;
		ans-=maxAp(u[i-1],u[i]);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;const int N=2e5+7;
int L[N],R[N],a[N],n,i,j,k,sum,limit,mx,ans,mp[N];
int main(){
    scanf("%d%*d",&n);
    for(i=1;i<=n;++i){
        scanf("%d",a+i);
        if(!L[a[i]])L[a[i]]=i;else R[a[i]]=i;
    }
    for(i=1;i<=n;i=limit+1){
        for(limit=R[a[i]];j<=limit;++j)
            limit=max(limit,R[a[j]]);
        sum=limit-i+1;mx=0;
        for(k=i;k<=limit;++k)mp[a[k]]++;
        for(k=i;k<=limit;++k)mx=max(mx,mp[a[k]]),mp[a[k]]=0;
      //  printf("%d\n",mx);
        ans+=sum-mx;
    }printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;const int N=2e5+7;
int L[N],R[N],a[N],n,i,j,k,sum,limit,mx,ans,mp[N];
int main(){
    scanf("%d%*d",&n);
    for(i=1;i<=n;++i){
        scanf("%d",a+i);
        if(!L[a[i]])L[a[i]]=i;R[a[i]]=i;
    }
    for(i=1;i<=n;i=limit+1){
        for(limit=R[a[i]];j<=limit;++j)
            limit=max(limit,R[a[j]]);
        sum=limit-i+1;mx=0;
        for(k=i;k<=limit;++k)mp[a[k]]++;
        for(k=i;k<=limit;++k)mx=max(mx,mp[a[k]]),mp[a[k]]=0;
      //  printf("%d\n",mx);
        ans+=sum-mx;
    }printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;const int N=2e5+7;
int L[N],R[N],a[N],n,i,j,k,sum,limit,mx,ans;map<int,int>mp;
int main(){
    scanf("%d%*d",&n);
    for(i=1;i<=n;++i){
        scanf("%d",a+i);
        if(!L[a[i]])L[a[i]]=i;else R[a[i]]=i;
    }
    for(i=1;i<=n;i=limit+1){
        for(limit=R[a[i]];j<=limit;++j)
            limit=max(limit,R[a[j]]);
        mp.clear();sum=limit-i+1;mx=0;
        for(k=i;k<=limit;++k)mp[a[k]]++;
        for(auto&x:mp)mx=max(mx,x.second);
      //  printf("%d\n",mx);
        ans+=sum-mx;
    }printf("%d\n",ans);
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <deque>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename KeyType=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<KeyType>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>using ordered_set_t=__gnu_pbds::tree<KeyType,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>;const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>using hash_table_t=__gnu_pbds::gp_hash_table<KeyType,int,ghash>;namespace vh{template<class T>struct like_array:is_array<T>{};template<class T,size_t N>struct like_array<array<T,N>>:true_type{};template<class T>struct like_array<vector<T>>:true_type{};template<class T>bool is_like_array(const T&a){return like_array<T>::value;}template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}template<typename T>inline void _R(vector<T>&v,size_t ie){for(int i=0;i<ie;i++)_R(v[i]);}template<typename T>inline void _R(vector<T>&v){_R(v,v.size());}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}template<typename T>inline void _W(vector<T>&v,size_t ie){for(int i=0;i<ie;i++){if(i>0)_W(' ');_W(v[i]);}_W('\n');}template<typename T>inline void _W(vector<T>&v){_W(v,v.size());}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}template<class T>void _RE(T&x){cin>>x;}template<class Arg,class... Args>void _RE(Arg&first,Args&... rest);void _RE(double&x){string t;_RE(t);x=stod(t);}void _RE(long double&x){string t;_RE(t);x=stold(t);}template<class T>void _RE(complex<T>&x);template<class T1,class T2>void _RE(pair<T1,T2>&p);template<class T>void _RE(vector<T>&a);template<class T,size_t SZ>void _RE(array<T,SZ>&a);template<class Arg,class... Args>void _RE(Arg&first,Args&... rest){_RE(first);_RE(rest...);}template<class T>void _RE(complex<T>&x){T a,b;_RE(a,b);x=cd(a,b);}template<class T1,class T2>void _RE(pair<T1,T2>&p){_RE(p.f,p.s);}template<class T>void _RE(vector<T>&a){for(int i=0,ie=sz(a);i<ie;i++)_RE(a[i]);}template<class T,size_t SZ>void _RE(array<T,SZ>&a){for(int i=0;i<SZ;i++)_RE(a[i]);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<typename T>inline T isqrt(T k){T r=sqrt((double)k)+1;while(r*r>k)r--;return r;}template<typename T>inline T icbrt(T k){T r=cbrt((double)k)+1;while(r*r*r>k)r--;return r;}template<typename T>bool mul_overflow(T&r,T a,T b){return __builtin_mul_overflow(a,b,&r);}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define TREESIZE(n) ((1<<(BitSize<n>::Size + 1))+7)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(),(x).rend()
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;};template<typename T>class StackGuard{private:T x;public:StackGuard(T x):x(x){}~StackGuard(){x();}};}namespace vh{};
namespace vh{
  const int maxn=200200;
  int n,q;
  int a[maxn];
  int mi[maxn],ma[maxn];
  int cnt[maxn];
  int main(){
    srand(GRANDOM);
    cin>>n>>q;
    memset(mi,-1,sizeof(mi));
    memset(ma,-1,sizeof(ma));
    memset(cnt,0,sizeof(cnt));
    set<int>v;
    for(int i=0;i<n;i++){
      cin>>a[i];
      v.insert(a[i]);
      cnt[a[i]]++;
      if(mi[a[i]]<0)mi[a[i]]=ma[a[i]]=i;
      else ma[a[i]]=i;
    }
    vector<int>vi(v.begin(),v.end());
    sort(vi.begin(),vi.end(),[](int x,int y){
      if(mi[x]!=mi[y])return mi[x]<mi[y];
      if(ma[x]!=ma[y])return ma[x]>ma[y];
      return false;
    });
    int currma=-1;
    int ans=0;
    for(auto x:vi){
      if(mi[x]>currma){
        currma=ma[x];
      }else{
        ans+=cnt[x];
        currma=max(currma,ma[x]);
      }
    }
    cout<<ans<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <deque>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename KeyType=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<KeyType>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>using ordered_set_t=__gnu_pbds::tree<KeyType,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>;const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>using hash_table_t=__gnu_pbds::gp_hash_table<KeyType,int,ghash>;namespace vh{template<class T>struct like_array:is_array<T>{};template<class T,size_t N>struct like_array<array<T,N>>:true_type{};template<class T>struct like_array<vector<T>>:true_type{};template<class T>bool is_like_array(const T&a){return like_array<T>::value;}template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}template<typename T>inline void _R(vector<T>&v,size_t ie){for(int i=0;i<ie;i++)_R(v[i]);}template<typename T>inline void _R(vector<T>&v){_R(v,v.size());}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}template<typename T>inline void _W(vector<T>&v,size_t ie){for(int i=0;i<ie;i++){if(i>0)_W(' ');_W(v[i]);}_W('\n');}template<typename T>inline void _W(vector<T>&v){_W(v,v.size());}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}template<class T>void _RE(T&x){cin>>x;}template<class Arg,class... Args>void _RE(Arg&first,Args&... rest);void _RE(double&x){string t;_RE(t);x=stod(t);}void _RE(long double&x){string t;_RE(t);x=stold(t);}template<class T>void _RE(complex<T>&x);template<class T1,class T2>void _RE(pair<T1,T2>&p);template<class T>void _RE(vector<T>&a);template<class T,size_t SZ>void _RE(array<T,SZ>&a);template<class Arg,class... Args>void _RE(Arg&first,Args&... rest){_RE(first);_RE(rest...);}template<class T>void _RE(complex<T>&x){T a,b;_RE(a,b);x=cd(a,b);}template<class T1,class T2>void _RE(pair<T1,T2>&p){_RE(p.f,p.s);}template<class T>void _RE(vector<T>&a){for(int i=0,ie=sz(a);i<ie;i++)_RE(a[i]);}template<class T,size_t SZ>void _RE(array<T,SZ>&a){for(int i=0;i<SZ;i++)_RE(a[i]);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<typename T>inline T isqrt(T k){T r=sqrt((double)k)+1;while(r*r>k)r--;return r;}template<typename T>inline T icbrt(T k){T r=cbrt((double)k)+1;while(r*r*r>k)r--;return r;}template<typename T>bool mul_overflow(T&r,T a,T b){return __builtin_mul_overflow(a,b,&r);}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define TREESIZE(n) ((1<<(BitSize<n>::Size + 1))+7)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(),(x).rend()
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;};template<typename T>class StackGuard{private:T x;public:StackGuard(T x):x(x){}~StackGuard(){x();}};}namespace vh{};
namespace vh{
  const int maxn=200200;
  int n,q;
  int a[maxn];
  int mi[maxn],ma[maxn];
  int cnt[maxn];
  int main(){
    srand(GRANDOM);
    cin>>n>>q;
    memset(mi,-1,sizeof(mi));
    memset(ma,-1,sizeof(ma));
    memset(cnt,0,sizeof(cnt));
    for(int i=0;i<n;i++){
      cin>>a[i];
      cnt[a[i]]++;
      if(mi[a[i]]<0)mi[a[i]]=ma[a[i]]=i;
      else ma[a[i]]=i;
    }
    int cs=0,cmx=0,ce=-1;
    int ans=0;
    auto _commit=[&](){
      if(ce>=cs){
        ans+=(ce-cs+1)-cmx;
      }
    };
    for(int i=0;i<n;i++){
      if(i>ce){
        _commit();
        cs=i;cmx=cnt[a[i]];ce=ma[a[i]];
      }else{
        cmx=max(cmx,cnt[a[i]]);
        ce=max(ce,ma[a[i]]);
      }
    }
    _commit();
    cout<<ans<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}