#include <bits/stdc++.h>
#define K 1000000
using namespace std;

int p_arr[K];

void obradi(int gornji[], int donji[], int n, int h){
	int p_l, index_l, p_d, index_d;
	for (int i = 0; i < n; i++){
		if (donji[i] && i){
			p_d = 0;
			index_d = 0;
			for (int j = i + 1; j < n && !donji[j] && gornji[j]; j++){
				index_d++;
				p_d += gornji[j];
			}
			p_l = 0;
			index_l = 0;
			for (int j = i - 1; j >= 0 && !donji[j] && gornji[j]; j--){
				index_l++;
				p_l += gornji[j];
			}
			int d_l = 1, d_d = 1;

			if (i + index_d != n - 1) d_d = 2;
			if (index_l != i) d_l = 2;
			donji[i] = gornji[i] + (p_l / d_l) + (p_d / d_d);
			if (h % 2)	
				donji[i] += p_d % d_d;
			if (!(h % 2))
				donji[i] += p_l % d_l;

			i += index_d;
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, h;
	cin >> h >> n;

	int gornji[K], donji[K];
	for (int i = 0; i < n; i++)
		gornji[i] = 1;
	for (int i = 0; i < n; i++)
		cin >> donji[i];
	obradi(gornji, donji, n, 1);
	for (int i = 0; i < n; i++)
		cout << donji[i] << " ";
	cout << "\n";
	for (int i = 1; i < h; i++){
		for (int j = 0; j < n; j++){
			gornji[j] = donji[j];
			cin >> donji[j];
		}
		obradi(gornji, donji, n, i + 1);
			for (int i = 0; i < n; i++)
		cout << donji[i] << " ";
	cout << "\n";
	}

	for (int i = 0; i < n; i++)
		cout << donji[i] << " ";
	cout << "\n";

	return 0;
}