#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n, m;
	while (cin >> n >> m && (n || m)) {
		VI p(n); rep(i, n)cin >> p[i];
		sort(all(p)); reverse(all(p));

		int ans = 0;
		for (int i = 0; i < n; i += m) {
			for (int j = i; j < min(i + m - 1, n); j++) {
				ans += p[j];
			}
		}
		Cout(ans);
	}
}

#include <cstdio>

using namespace std;

int main()
{
	char mp[15][15] = {0};
	int pi, pj;
	int cnt;
	while (scanf("%s", mp[1]) != EOF){
		cnt = 0;
		
		for (int i = 2; i <= 12; i++) scanf("%s", mp[i]);
		
		for (int i = 1; i <= 12; i++){
			for (int j = 0; j < 12; j++){
				if (mp[i][j] == '1'){
					if(mp[i-1][j] != '2') {
						cnt++;
					}
					while(mp[i][j] != '0' && j < 12){
						mp[i][j] = '2';
						pi = i;
						while (mp[++pi][j] == '1'){
							pj = j;
							while(mp[pi][pj] == '1'){
								mp[pi][pj] = '2';
								pj--;
							}
							pj = j;
							while(mp[pi][++pj] == '1'){
								mp[pi][pj] = '2';
							}
						}
						j++;
					}
				}
			}
		}
		
		printf("%d\n", cnt);
	}
}