// Slower C++ solution:
#include <iostream>  

#include <cstdio>  

#include <cstring>  

#include <algorithm>  

using namespace std;  

const int maxn=2e5+100;  

int par[maxn],sum[maxn];  

int N,K,p,tot;  

void intt(int n)  

{  

    for(int i=0;i<=n;i++)  

        par[i]=i;  

}  

  

int find(int x)  

{  

    if(par[x]==x)  

        return x;  

    return par[x]=find(par[x]);  

}  

void unit(int x,int y)  

{  

    int fx=find(x),fy=find(y);  

    if(fx!=fy)  

        par[fx]=fy;  

}  

bool same(int x,int y)  

{  

    return find(x)==find(y);  

}  

int main()  

{  

    while(~scanf("%d%d",&N,&K))  

    {  

        int ans=0;  

        memset(sum,0,sizeof(sum));  

        memset(par,0,sizeof(par));  

        tot=0;  

        intt(N);  

        int t;  

        scanf("%d",&t);  

        sum[t]++;  

        p=t;  

        tot++;  

        for(int i=2;i<=N;i++)  

        {  

            scanf("%d",&t);  

            sum[t]++;  

            if(!same(t,p))  

            {  

                tot++;  

                unit(t,p);  

            }  

        }  

        sort(sum,sum+N+1);  

        if(tot<=K)  

            ans=0;  

        else  

        {  

            int cnt=tot-K;  

            int pos=lower_bound(sum,sum+N+1,1)-sum;  

            while(cnt--)  

                ans+=sum[pos++];         

        }  

        printf("%d\n",ans);  

    }  

    return 0;  

}  

// Faster C++ solution for the same problem (measured speedup: 2.7898159894900614x):
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int INF = 1e9;

const ll LINF = 1e18;

template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }

template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }

template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }

template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }



/*

 <url:>

 問題文============================================================

 =================================================================

 解説=============================================================

 ================================================================

 */





ll solve(){

    ll res = 0;

    map<ll,ll> mp;

    ll N,K; cin >> N >> K;

    for(int i = 0; i < N;i++){

        ll A; cin >> A;

        mp[A]++;

    }

    vector<pll> ps;

    for(auto it = mp.begin();it!=mp.end(); it++){

        ps.push_back({it->second,it->first});

    }

    sort(ps.begin(),ps.end());

    ll Size = (ll)ps.size();

    for(int i = 0; i < ps.size();i++){

        if(Size <= K) break;

        res += ps[i].first;

        Size--;

    }

    return res;

}

int main(void) {

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

    cout << solve() << endl;

    return 0;

}