#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector< pii >
#define vpll vector< pll >
#define mpii map<int,int>
#define mpll map<ll,ll>
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define s(v) v.size()
#define test ll t;cin>>t;while(t--)
#define vec vector<ll>
#define read0(v,n) for(int i=0;i<n;i++)cin>>v[i];
#define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i];
#define trav(a,x) for (auto& a: x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cut(x) {cout<<x;return 0;}
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define nl '\n'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
ll gcd(ll a, ll b)
{
	if (b==0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
ll pow(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}

int main()
{
	fast
	int n,k;
	cin>>n>>k;
	vec v(n);
	read0(v,n);
	mpll m;
	trav(it,v)m[it]++;
	vec temp[k];
	ll prev=m[0]-1;
	FOR(i,0,n-1)
	{
	    prev=min(prev,m[i]-1);
	    FOR(j,0,min((ll)k-1,prev))
	    {
	        temp[j].pb(1);
	    }
	}
	ll ans=0;
	FOR(i,0,k-1)
	{
	    ans+=s(temp[i]);
	}
	cout<<ans<<nl;
}

/*-------------必要なときに使うもの------------------*/
//#define _GLIBCXX_DEBUG
/*#include<atcoder/modint>
#include<atcoder/math>
using namespace atcoder;
using mint=modint1000000007;
using MINT=modint998244353;*/
/*#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")*/
/*-------------------end-----------------------------*/
#include<bits/stdc++.h>
using namespace std;
/*---------------------マクロ-------------------------*/
#define int long long
#define rep(i, n) for (int i = 0; i < (long long)(n); i++)
#define stoi stoll
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout<<#x<<" : "<<x<<endl
#define endl '\n'
/*------------------------end---------------------------*/
/*-----------------------型エイリアス--------------------*/
using ll = long long;
using lint=long long;
using P=pair<long long,long long>;
using vi=vector<long long>;
using vvi=vector<vi>;
using vb=vector<bool>;
using vc=vector<char>;
using vvc=vector<vc>;
using vs=vector<string>;
using vd=vector<double>;
/*------------------------end---------------------------*/
/* ----------------よく使う数字や配列-------------------- */
constexpr long long INF = LLONG_MAX/3;
constexpr long long dx[]={1,0,-1,0},dy[]={0,1,0,-1};
constexpr long long mod = 1e9 + 7;
constexpr long long MOD=998244353;
constexpr long double pi = 3.141592653589793238462643383279;
constexpr double EPS=1e-14;
/* ----------------------end-----------------------------*/
/*---------------------template------------------------*/
template<class T>inline bool chmin(T& a,T b){
  if(a>b){a=b;return true;}
  return false;
}
template<class T>inline bool chmax(T& a,T b){
  if(a<b){a=b;return true;}
  return false;
}
template<class T>inline void mainend(T x){cout<<x<<endl;exit(0);}
/*----------------------end-------------------------*/
void Main(){
  int N,K;cin>>N>>K;
  map<int,int>mp;
  int MAX=-INF;
  rep(i,N){int a;cin>>a;chmax(MAX,a);mp[a]++;}
  for(int i=0;i<=MAX;i++){
    if(!mp.count(i))mp[i]=0;
  }
  map<int,pair<set<int>,int>>ma;
  for(auto&[x,y]:mp){
    ma[y].first.insert(x);
  }
  for(auto &[x,y]:ma){
    y.second=*y.first.begin();
  }
  if(!ma.count(0)){
    ma[0].first.insert(MAX+1);
    ma[0].second=MAX+1;
  }
  int t_min=ma[0].second;
  int sum=0;
  /*for(auto[x,y]:ma){
    cout<<'%'<<x<<'%'<<endl;
    for(auto z:y.first){
      cout<<z<<' ';
    }
    cout<<endl;
  }*/
  
  for(int i=0;i<K;i++){
    int a;
    if(!ma.count(i))a=t_min;
    else a=ma[i].second;
    //debug(a);
    chmin(t_min,a);
    sum+=t_min;
  }
  cout<<sum<<endl;
  
}
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(16);
  Main();
}