#include<bits/stdc++.h>
using namespace std;
long long arr[300010];
long long arr2[300010];
int main()
{

    long long a,b,c,d,e,i,j;
    cin >> a >> b;

    long long k=0,chk=0;
    for(i=0;i<a;i++)
    {
        cin >> d;
        arr[d]++;
        chk=max(d,chk);
        k=max(arr[d],k);

    }
    for(i=0;i<=chk;i++){
            if(i==0)
       arr2[i]=min(arr[i],b);
      else{
        arr2[i]=min(arr[i],arr2[i-1]);
      }
      if(arr2[i]==0)
        break;

    }
    long long past=0,sum=0;
    for(i=chk;i>=0;i--){
            long long present=arr2[i];
            sum=sum+(present-past)*(i+1);
            past=present;


    }
    cout << sum << endl;


}

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

int main(){
  int N, X;
  cin >> N >> X;
  int tmp = 0;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if (A != X){
      if (tmp != 0){
        cout << " ";
      }
      cout << A;
      tmp++;
    }
  }
  cout << endl;
}