stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int xx[5000000];

int main()

{

    int n,k,v,c=0;

    cin>>n>>k;

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

    {

        cin>>v;

        xx[v]++;

    }

    vector<int>vc;

    for(int i=1;i<=200000;i++)

    {

        if(xx[i]!=0)vc.push_back(xx[i]);

    }



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

    int si=vc.size();

    si-=k;

    if(si<=0)cout<<"0"<<endl;

    else{

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

            c+=vc[i];

        cout<<c<<endl;

    }



    return 0;

}


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

using namespace std;

int main()

{

    int a,b,c,d,e,f,g,h;

    int i,j;

    cin>>a>>b;

    int ar[a];

    map<int,int>m;

    map<int,int>::iterator it;

    set<int>s;

    for(i=0;i<a;i++)

    {

        cin>>ar[i];

        m[ar[i]]++;



    }

    vector<int>v;

    c=m.size();

    for(it=m.begin();it!=m.end();it++)

    {

        v.push_back((*it).second);





    }

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

    if(b>=c)

    {

        cout<<"0"<<endl;

    }

    else{

        int k=c-b;

        d=0;e=0;

        for(i=0;i<v.size();i++)

        {

            k-=1;

            d+=v[i];

            if(k<=0)

            {

                break;

            }

        }

        cout<<d<<endl;

    }



    m.clear();

    v.clear();

    return 0;





}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> // Common file

#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#include <ext/pb_ds/detail/standard_policies.hpp>



using namespace std;

using namespace __gnu_pbds;



typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,

		tree_order_statistics_node_update> ordered_set;



#define el				'\n'

#define sz(v)			((int)((v).size()))

#define all(v)          ((v).begin()),((v).end())

#define clr(v, d)		memset(v, d, sizeof(v))



double const EPS = 1e-8, PI = acos(-1);

const int N = 200000 + 9, M = 20 + 9, OO = (int) 1e9 + 1;

const long long MOD = 1e9 + 7, INF = 1e18 + 9;



typedef long long ll;



void OUTPUT() {

	cout << fixed << setprecision(0);

	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

}



void INPUT() {

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

//	freopen("output.txt", "w", stdout);

#endif

}



int n, k, x, arr[N];



int main() {

//	INPUT();

	OUTPUT();

	cin >> n >> k;

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

		cin >> x;

		arr[x]++;

	}

	vector<int> v;

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

		if (arr[i])

			v.push_back(arr[i]);

	}

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

	ll ans = 0;

	int m = max(0, sz(v) - k);

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

		ans += v[i];

	}

	cout << ans;



	return 0;



}




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

using namespace std;

#define ll long long

#define F first

#define S second

int main()

{

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

    ll n, k, ans = 0;

    cin >> n >> k;

    map<ll, ll>mp;

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

    {

        ll x;

        cin >> x;

        ++mp[x];

    }

    set<pair<ll, ll>>st;

    for(auto &it : mp)

        st.insert({it.S, it.F});

    while(st.size() > k)

    {

        auto it = st.begin();

        ans += it->F;

        st.erase(it);

    }

    cout << ans;

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int xx[5000000];

int main()

{

    int n,k,v,c=0;

    cin>>n>>k;

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

    {

        cin>>v;

        xx[v]++;

    }

    vector<int>vc;

    for(int i=1;i<=200000;i++)

    {

        if(xx[i]!=0)vc.push_back(xx[i]);

    }



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

    int si=vc.size();

    si-=k;

    if(si<=0)cout<<"0"<<endl;

    else{

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

            c+=vc[i];

        cout<<c<<endl;

    }



    return 0;

}


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

using namespace std;

#define ll long long

#define F first

#define S second

int main()

{

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

    ll n, k, ans = 0;

    cin >> n >> k;

    map<ll, ll>mp;

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

    {

        ll x;

        cin >> x;

        ++mp[x];

    }

    set<pair<ll, ll>>st;

    for(auto &it : mp)

        st.insert({it.S, it.F});

    while(st.size() > k)

    {

        auto it = st.begin();

        ans += it->F;

        st.erase(it);

    }

    cout << ans;

    return 0;

}
// Slower C++ solution:
//#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pll;

#define mp make_pair

#define f first

#define s second

#define pb push_back



const int N = 2e5 + 5;

const int OO = 2e9;



int n,k,a[N],f[N],ans;

vector<int>  v;



void init() {







}



int main() {



    ios_base::sync_with_stdio(false);

    cin.tie(0);



    cin >> n >> k;



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



        cin >> a[i];

        f[a[i]]++;



    }



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



        if(f[i]) v.pb(f[i]);



    }



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



    for(int i=0;i<max(0,int(v.size())-k);++i) {



        ans += v[i];



    }



    cout << ans << '\n';



    return 0;



}

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

using namespace std;

#define ll long long

#define F first

#define S second

int main()

{

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

    ll n, k, ans = 0;

    cin >> n >> k;

    map<ll, ll>mp;

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

    {

        ll x;

        cin >> x;

        ++mp[x];

    }

    set<pair<ll, ll>>st;

    for(auto &it : mp)

        st.insert({it.S, it.F});

    while(st.size() > k)

    {

        auto it = st.begin();

        ans += it->F;

        st.erase(it);

    }

    cout << ans;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> // Common file

#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#include <ext/pb_ds/detail/standard_policies.hpp>



using namespace std;

using namespace __gnu_pbds;



typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,

		tree_order_statistics_node_update> ordered_set;



#define el				'\n'

#define sz(v)			((int)((v).size()))

#define all(v)          ((v).begin()),((v).end())

#define clr(v, d)		memset(v, d, sizeof(v))



double const EPS = 1e-8, PI = acos(-1);

const int N = 200000 + 9, M = 20 + 9, OO = (int) 1e9 + 1;

const long long MOD = 1e9 + 7, INF = 1e18 + 9;



typedef long long ll;



void OUTPUT() {

	cout << fixed << setprecision(0);

	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

}



void INPUT() {

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

//	freopen("output.txt", "w", stdout);

#endif

}



int n, k, x, arr[N];



int main() {

//	INPUT();

	OUTPUT();

	cin >> n >> k;

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

		cin >> x;

		arr[x]++;

	}

	vector<int> v;

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

		if (arr[i])

			v.push_back(arr[i]);

	}

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

	ll ans = 0;

	int m = max(0, sz(v) - k);

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

		ans += v[i];

	}

	cout << ans;



	return 0;



}




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

#define S second

#define F first

#define ll long long



using namespace std;



const int N = 2e5 + 5;



int arr[N], grid[200][200];



int main()

{

    map<int, int> mop;

    int n, xx, k;

    scanf("%d%d", &n, &k);

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

    {

        scanf("%d", &xx);

        mop[xx]++;

    }

    vector<pair<int, int> > v;

    for(auto i:mop) v.emplace_back(i.S, i.F);

    sort(v.rbegin(), v.rend());

    int ans = 0;

    for(int i = k ; i < v.size() ; i++) ans += v[i].F;

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

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int xx[5000000];

int main()

{

    int n,k,v,c=0;

    cin>>n>>k;

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

    {

        cin>>v;

        xx[v]++;

    }

    vector<int>vc;

    for(int i=1;i<=200000;i++)

    {

        if(xx[i]!=0)vc.push_back(xx[i]);

    }



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

    int si=vc.size();

    si-=k;

    if(si<=0)cout<<"0"<<endl;

    else{

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

            c+=vc[i];

        cout<<c<<endl;

    }



    return 0;

}


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

#define S second

#define F first

#define ll long long



using namespace std;



const int N = 2e5 + 5;



int arr[N], grid[200][200];



int main()

{

    map<int, int> mop;

    int n, xx, k;

    scanf("%d%d", &n, &k);

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

    {

        scanf("%d", &xx);

        mop[xx]++;

    }

    vector<pair<int, int> > v;

    for(auto i:mop) v.emplace_back(i.S, i.F);

    sort(v.rbegin(), v.rend());

    int ans = 0;

    for(int i = k ; i < v.size() ; i++) ans += v[i].F;

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

    return 0;

}
// Slower C++ solution:
//#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pll;

#define mp make_pair

#define f first

#define s second

#define pb push_back



const int N = 2e5 + 5;

const int OO = 2e9;



int n,k,a[N],f[N],ans;

vector<int>  v;



void init() {







}



int main() {



    ios_base::sync_with_stdio(false);

    cin.tie(0);



    cin >> n >> k;



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



        cin >> a[i];

        f[a[i]]++;



    }



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



        if(f[i]) v.pb(f[i]);



    }



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



    for(int i=0;i<max(0,int(v.size())-k);++i) {



        ans += v[i];



    }



    cout << ans << '\n';



    return 0;



}

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

#define S second

#define F first

#define ll long long



using namespace std;



const int N = 2e5 + 5;



int arr[N], grid[200][200];



int main()

{

    map<int, int> mop;

    int n, xx, k;

    scanf("%d%d", &n, &k);

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

    {

        scanf("%d", &xx);

        mop[xx]++;

    }

    vector<pair<int, int> > v;

    for(auto i:mop) v.emplace_back(i.S, i.F);

    sort(v.rbegin(), v.rend());

    int ans = 0;

    for(int i = k ; i < v.size() ; i++) ans += v[i].F;

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

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> // Common file

#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#include <ext/pb_ds/detail/standard_policies.hpp>



using namespace std;

using namespace __gnu_pbds;



typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,

		tree_order_statistics_node_update> ordered_set;



#define el				'\n'

#define sz(v)			((int)((v).size()))

#define all(v)          ((v).begin()),((v).end())

#define clr(v, d)		memset(v, d, sizeof(v))



double const EPS = 1e-8, PI = acos(-1);

const int N = 200000 + 9, M = 20 + 9, OO = (int) 1e9 + 1;

const long long MOD = 1e9 + 7, INF = 1e18 + 9;



typedef long long ll;



void OUTPUT() {

	cout << fixed << setprecision(0);

	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

}



void INPUT() {

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

//	freopen("output.txt", "w", stdout);

#endif

}



int n, k, x, arr[N];



int main() {

//	INPUT();

	OUTPUT();

	cin >> n >> k;

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

		cin >> x;

		arr[x]++;

	}

	vector<int> v;

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

		if (arr[i])

			v.push_back(arr[i]);

	}

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

	ll ans = 0;

	int m = max(0, sz(v) - k);

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

		ans += v[i];

	}

	cout << ans;



	return 0;



}




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

using namespace std;

#define x_ real()

#define y_ imag()

#define cross(a, b) (conj(a)*(b)).imag()

#define dot(a, b) (conj(a)*(b)).real()

#define PI acos(-1)

#define F first

#define S second

#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)

#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long double ld;

typedef long long ll;

typedef unsigned long long ull;

typedef complex<ld> point;

typedef tuple<int, int, int> line;

typedef vector<point> polygon;

typedef pair<double, double> pd;

pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };







int main() {

	fastIO;

	int n, k;

	cin >> n >> k;

	vector<pair<int, int>> v;

	map<int, int> frq;

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

		int x;

		cin >> x;

		frq[x]++;

	}



	for (auto i : frq) {

		v.push_back({i.second, i.first});

	}



	sort(v.rbegin(), v.rend());

	ll ans = 0;

	while(v.size() > k) {

		ans += v.back().first;

		v.pop_back();

	}





	cout << ans;





}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int xx[5000000];

int main()

{

    int n,k,v,c=0;

    cin>>n>>k;

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

    {

        cin>>v;

        xx[v]++;

    }

    vector<int>vc;

    for(int i=1;i<=200000;i++)

    {

        if(xx[i]!=0)vc.push_back(xx[i]);

    }



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

    int si=vc.size();

    si-=k;

    if(si<=0)cout<<"0"<<endl;

    else{

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

            c+=vc[i];

        cout<<c<<endl;

    }



    return 0;

}


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

using namespace std;

#define x_ real()

#define y_ imag()

#define cross(a, b) (conj(a)*(b)).imag()

#define dot(a, b) (conj(a)*(b)).real()

#define PI acos(-1)

#define F first

#define S second

#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)

#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long double ld;

typedef long long ll;

typedef unsigned long long ull;

typedef complex<ld> point;

typedef tuple<int, int, int> line;

typedef vector<point> polygon;

typedef pair<double, double> pd;

pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };







int main() {

	fastIO;

	int n, k;

	cin >> n >> k;

	vector<pair<int, int>> v;

	map<int, int> frq;

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

		int x;

		cin >> x;

		frq[x]++;

	}



	for (auto i : frq) {

		v.push_back({i.second, i.first});

	}



	sort(v.rbegin(), v.rend());

	ll ans = 0;

	while(v.size() > k) {

		ans += v.back().first;

		v.pop_back();

	}





	cout << ans;





}
// Slower C++ solution:
//#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pll;

#define mp make_pair

#define f first

#define s second

#define pb push_back



const int N = 2e5 + 5;

const int OO = 2e9;



int n,k,a[N],f[N],ans;

vector<int>  v;



void init() {







}



int main() {



    ios_base::sync_with_stdio(false);

    cin.tie(0);



    cin >> n >> k;



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



        cin >> a[i];

        f[a[i]]++;



    }



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



        if(f[i]) v.pb(f[i]);



    }



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



    for(int i=0;i<max(0,int(v.size())-k);++i) {



        ans += v[i];



    }



    cout << ans << '\n';



    return 0;



}

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

using namespace std;

#define x_ real()

#define y_ imag()

#define cross(a, b) (conj(a)*(b)).imag()

#define dot(a, b) (conj(a)*(b)).real()

#define PI acos(-1)

#define F first

#define S second

#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)

#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long double ld;

typedef long long ll;

typedef unsigned long long ull;

typedef complex<ld> point;

typedef tuple<int, int, int> line;

typedef vector<point> polygon;

typedef pair<double, double> pd;

pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };







int main() {

	fastIO;

	int n, k;

	cin >> n >> k;

	vector<pair<int, int>> v;

	map<int, int> frq;

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

		int x;

		cin >> x;

		frq[x]++;

	}



	for (auto i : frq) {

		v.push_back({i.second, i.first});

	}



	sort(v.rbegin(), v.rend());

	ll ans = 0;

	while(v.size() > k) {

		ans += v.back().first;

		v.pop_back();

	}





	cout << ans;





}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> // Common file

#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#include <ext/pb_ds/detail/standard_policies.hpp>



using namespace std;

using namespace __gnu_pbds;



typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,

		tree_order_statistics_node_update> ordered_set;



#define el				'\n'

#define sz(v)			((int)((v).size()))

#define all(v)          ((v).begin()),((v).end())

#define clr(v, d)		memset(v, d, sizeof(v))



double const EPS = 1e-8, PI = acos(-1);

const int N = 200000 + 9, M = 20 + 9, OO = (int) 1e9 + 1;

const long long MOD = 1e9 + 7, INF = 1e18 + 9;



typedef long long ll;



void OUTPUT() {

	cout << fixed << setprecision(0);

	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

}



void INPUT() {

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

//	freopen("output.txt", "w", stdout);

#endif

}



int n, k, x, arr[N];



int main() {

//	INPUT();

	OUTPUT();

	cin >> n >> k;

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

		cin >> x;

		arr[x]++;

	}

	vector<int> v;

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

		if (arr[i])

			v.push_back(arr[i]);

	}

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

	ll ans = 0;

	int m = max(0, sz(v) - k);

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

		ans += v[i];

	}

	cout << ans;



	return 0;



}




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

using namespace std;



#define VIC ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);

#define wtf(s) freopen((s), "w", stdout)

#define rff(s) freopen((s), "r", stdin)

#define pi (2 * acos(0))

typedef long double ld;

typedef long long ll;

typedef complex<ld> point;

#define endl '\n'

#define matrix vector<vector<ll>>

#define EPS 1e-9

#define X real()

#define Y imag()

#define vec(a, b) ((b) - (a))

#define dot(a, b) ((conj(a) * (b)).real())

#define cross(a, b) ((conj(a) *(b)).imag())

#define lengthsqr(v) (dot(v, v))

#define length(v) ((ld)hypot((v).Y, (v).X))

#define same(a, b) (lengthsqr(vec(a, b)) < EPS)



const int N = 2e5 + 5, inf = 2e9;

const ll mod = 1e9 + 7;



int a[N];



int main()

{

    VIC

    int n, ans = 0, k, x;

    cin >> n >> k;

    set<int> s;

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

        cin >> x,

        s.insert(x),

        a[x]++;

    sort(a, a + n + 1);

    int c = 0;

    for (int i = 0; i < n && c < (int)s.size() - k; i++)

        ans += a[i],

        c += (a[i] != 0);

    cout << ans;

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int xx[5000000];

int main()

{

    int n,k,v,c=0;

    cin>>n>>k;

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

    {

        cin>>v;

        xx[v]++;

    }

    vector<int>vc;

    for(int i=1;i<=200000;i++)

    {

        if(xx[i]!=0)vc.push_back(xx[i]);

    }



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

    int si=vc.size();

    si-=k;

    if(si<=0)cout<<"0"<<endl;

    else{

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

            c+=vc[i];

        cout<<c<<endl;

    }



    return 0;

}


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

using namespace std;



#define VIC ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);

#define wtf(s) freopen((s), "w", stdout)

#define rff(s) freopen((s), "r", stdin)

#define pi (2 * acos(0))

typedef long double ld;

typedef long long ll;

typedef complex<ld> point;

#define endl '\n'

#define matrix vector<vector<ll>>

#define EPS 1e-9

#define X real()

#define Y imag()

#define vec(a, b) ((b) - (a))

#define dot(a, b) ((conj(a) * (b)).real())

#define cross(a, b) ((conj(a) *(b)).imag())

#define lengthsqr(v) (dot(v, v))

#define length(v) ((ld)hypot((v).Y, (v).X))

#define same(a, b) (lengthsqr(vec(a, b)) < EPS)



const int N = 2e5 + 5, inf = 2e9;

const ll mod = 1e9 + 7;



int a[N];



int main()

{

    VIC

    int n, ans = 0, k, x;

    cin >> n >> k;

    set<int> s;

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

        cin >> x,

        s.insert(x),

        a[x]++;

    sort(a, a + n + 1);

    int c = 0;

    for (int i = 0; i < n && c < (int)s.size() - k; i++)

        ans += a[i],

        c += (a[i] != 0);

    cout << ans;

    return 0;

}
// Slower C++ solution:
//#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pll;

#define mp make_pair

#define f first

#define s second

#define pb push_back



const int N = 2e5 + 5;

const int OO = 2e9;



int n,k,a[N],f[N],ans;

vector<int>  v;



void init() {







}



int main() {



    ios_base::sync_with_stdio(false);

    cin.tie(0);



    cin >> n >> k;



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



        cin >> a[i];

        f[a[i]]++;



    }



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



        if(f[i]) v.pb(f[i]);



    }



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



    for(int i=0;i<max(0,int(v.size())-k);++i) {



        ans += v[i];



    }



    cout << ans << '\n';



    return 0;



}

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

using namespace std;



#define VIC ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);

#define wtf(s) freopen((s), "w", stdout)

#define rff(s) freopen((s), "r", stdin)

#define pi (2 * acos(0))

typedef long double ld;

typedef long long ll;

typedef complex<ld> point;

#define endl '\n'

#define matrix vector<vector<ll>>

#define EPS 1e-9

#define X real()

#define Y imag()

#define vec(a, b) ((b) - (a))

#define dot(a, b) ((conj(a) * (b)).real())

#define cross(a, b) ((conj(a) *(b)).imag())

#define lengthsqr(v) (dot(v, v))

#define length(v) ((ld)hypot((v).Y, (v).X))

#define same(a, b) (lengthsqr(vec(a, b)) < EPS)



const int N = 2e5 + 5, inf = 2e9;

const ll mod = 1e9 + 7;



int a[N];



int main()

{

    VIC

    int n, ans = 0, k, x;

    cin >> n >> k;

    set<int> s;

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

        cin >> x,

        s.insert(x),

        a[x]++;

    sort(a, a + n + 1);

    int c = 0;

    for (int i = 0; i < n && c < (int)s.size() - k; i++)

        ans += a[i],

        c += (a[i] != 0);

    cout << ans;

    return 0;

}