#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define IOS std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
using namespace std;

// DEBUG TEMPLATE
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}

void OFFLINE(){
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
        #define debug(x...) cout << "[" << #x << "] = ["; _print(x)
        #else
            #define debug(x...)
    #endif
}

const int MOD = 1e9 + 7;
int main(){

    IOS;
    OFFLINE();
    //check for corner test cases

    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    vector<vector<int>> brr(k);
    for(auto &x: arr)   cin >> x;
    sort(all(arr));
    
    if(arr[0] != 0) {
        cout << 0 << "\n";
        return 0;
    }

    int pos = 0, prev = 0, i = 0;
    while(i < n) {
        if(prev != arr[i]) {
            pos = 0;
        }
        if(brr[pos].empty()) {
            if(arr[i] == 0) {
                brr[pos].pb(arr[i]);
            }
        } else {
            if(brr[pos].back() + 1 >= arr[i]) {
                brr[pos].pb(arr[i]);
            }
        }
        prev = arr[i];
        i++;
        pos = (pos + 1) % k;
    }

    int ans = 0;
    for(int i = 0; i < k; i++) {
        if(!brr[i].empty()) {
            ans += brr[i].back() + 1;
        }
    }

    cout << ans << "\n";
    //check for corner test cases
    return 0;
}
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0 ; i < (n); ++i)
using namespace std ;
typedef long long ll ;
const int mod=1000000007;
const int N=1e3 ;

void solve(){

	int n,k;
	cin>>n>>k ;

	vector<int> a(n) ;

	rep(i,n){
		cin>>a[i] ;
	}

	map<int,int> mp ;

	for(int i=0;i<n;i++){
		mp[a[i]]++ ;
	}

	int mn=k ;
	
	ll ans=0 ;
	
	for(int i=0;i<=n;i++){
		mn=min(mn,mp[i]) ;
		ans+=mn ;
	}

	cout<<ans ;


}	

int main(){
 
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin) ;
		freopen("output.txt","w",stdout) ;
    #endif 

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

		int y ;

		y=1 ;
		//cin>>y ;

		while(y--){
 
			solve() ;
			
		}

		return 0 ;
}