#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n,m;
	while(cin >> n >> m,n){
		int p[1000],sum = 0;
		for(int i = 0;i < n;i++) cin >> p[i];
		sort(p,p + n,greater<int>());
		for(int i = 0;i < n;i++){
			if(i % m != m - 1) sum += p[i];
		}
		cout << sum << endl;
	}
	return 0;
}
// abc060_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, T;
    cin >> N >> T;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    ll ans = 0;
    ll l = 0;
    ll r = 0;
    REP(i, N){
        if (r < A[i]){
            ans += r - l;
            l = A[i];
            r = A[i] + T;
        } else {
            r = A[i] + T;
        }
    }
    ans += r - l;
    print(ans);

    return 0;
}
