#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()

typedef int64_t ll;
typedef uint64_t ull;

using namespace std;


void one_case() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto& el : a) cin >> el;

    sort(all(a));
    vector<int> bx(k);

    int prev = -1;
    int pos = 0;

    for (auto el : a) {
        if (el != prev) {
            pos = 0;
        }
        prev = el;
        if (pos == k) {
            continue;
        }
        if (pos == 0 && el > bx[pos]) {
            break;
        }
        if (el == bx[pos]) {
            ++bx[pos++];

        }

    }


    cout << accumulate(all(bx), 0ll);


}




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


    int t = 1;
//    cin >> t;
    for (int i = 0; i < t; ++i) {
        one_case();
    }

    return 0;
}


 /*
    Stay motivated and keep working hard
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define int long long 
#define pb push_back
#define cntbit __builtin_popcount
#define fr first
#define mem(arr, val) memset(arr, val, sizeof(arr))
#define sc second
#define sz(v) ((int)(v).size())
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repd(i,a,p) for(int i=a-1;i>=p;i--) 
#define md 998244353
#define vi vector<int>
#define vp vector<pair<int,int> >
#define ml map<int,int>
#define MPI 3.1415926536
#define in insert
#define endl "\n"
#define ub  upper_bound
#define lb  lower_bound
#define gcd __gcd
#define setval(a,b) memset(a,b,sizeof(a))
#define lwr lower_bound
#define pii pair<int,int>
#define upr upper_bound
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//CANDIDATE MASTER TOH BNKE RHUNGA
//dsu is pel concept
//KMP is pel concept 
int k,n,t,i,j=0,m;
const int N=1e6+5;
int md2;
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
 
inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}
 
inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}
 
inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
 
inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += md;
  return u;
}
void extgcd(int a,int b, int& x,int& y)
{
    if(b != 0){
        extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1;
        y = 0;
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>k;
    vi v(n);
    multiset <int> st;
	for(int i=0;i<n;i++)
    {
    	cin>>v[i];
    	st.insert(v[i]);
	}
	int ans=0;
	while(k)
	{
		for(i=0;i<=n;i++)
		{
			auto it=st.find(i);
			if(it==st.end())
			break;
			st.erase(it);
		}
		ans+=i;
		k--;
	}
	cout<<ans<<endl;
}
