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

int main(){
  int n,m;
  bool f[500][500];
  bool ans[500];
  int a,b;

  for(;;){
    cin >> n >> m;
    if(!n && !m)break;

    for(int i=0;i<n;i++){
      ans[i] = false;
      for(int j=0;j<n;j++)f[i][j] = false;
    }

    while(m--){
      cin >> a >> b;
      a--;
      b--;
      f[a][b] = true;
      f[b][a] = true;
      if(!a)ans[b] = true;
      if(!b)ans[a] = true;
    }

    for(int i=0;i<n;i++)
      if(f[0][i])
	for(int j=0;j<n;j++)ans[j] |= f[i][j];

    cout << count(ans+1,ans+n,true) << endl;
  }
}
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<int> p(n);
        for(int i=0; i<n; ++i)
            cin >> p[i];
        sort(p.rbegin(), p.rend());

        for(int i=m-1; i<n; i+=m)
            p[i] = 0;
        cout << accumulate(p.begin(), p.end(), 0) << endl;
    }
}