#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n, m;
  while((n = getInt()) + (m = getInt())){
    vector<int> v(n);
    int ans = 0;
    REP(i,n) v[i] = getInt();
    sort(v.rbegin(), v.rend());
    REP(i,n) if(i % m != (m - 1))
      ans += v[i];
    print(ans);
  }
  return 0;
}

#include <iostream>
#include <set>

int main(){
    while (true) {
        int n;  // I will buy n vegetables.
        int m;  // One bag contains m vegetables.
        
        std::cin >> n >> m;
        std::cin.ignore();
        if ( n==0 && m==0 ) {
            return 0;
        }
        
        // input vegetable's cost.
        std::multiset<int, std::greater<int> > buy;
        int in;
        for (int i=0; i < n ; ++i) {
            std::cin >> in;
            buy.insert(in);
        }
        
        int cost = 0;  // How much must I pay?
        int x = 1;  // This is the 'x'th vegetable in the bag.
        while ( ! buy.empty() ) {
            // the first item in 'buy' is the most expensive.
            std::set<int>::iterator it = buy.begin();
            // the 'm'th item in the bag is free!
            if ( x > m-1 ) {
                x = 1;
            }else{
                cost += *it;
                ++x;
            }
            buy.erase(it);
        }
        
        // output
        std::cout << cost << std::endl;
    }
    
    return 0;
}