// alias.cpp

// This solution reads the first image into a 2-dimensional

// array and then loops through it, printing out the

// anti-aliased image using the provided formula.

//


#include "stdlib.h"
#include "iostream.h"

#define MAX_ROWS 9
#define MAX_COLS 9

int main(int argc, char* argv[])
{
	char token[6];
	char line[MAX_COLS+1];
	char shade[2];
	int rows, cols;
	int i, j;

	int originalImage[MAX_ROWS][MAX_COLS];

	shade[1] = '\0';

	cin >> token;
	while (cin)
	{
		cin >> rows;
		cin >> cols;

		for (i = 0; i < rows; i++)
		{
			cin >> line;
			for (j = 0; j < cols; j++)
			{
				shade[0] = line[j];
				originalImage[i][j] = atoi(shade);
			}
		}
		

		for (i = 0; i < rows - 1; i++)
		{
			for (j = 0; j < cols - 1; j++)
			{
				cout << (originalImage[i][j] +
						 originalImage[i][j+1] +
						 originalImage[i+1][j] +
						 originalImage[i+1][j+1]) / 4;
			}
			cout << endl;
		}
		cin >> token;
		cin >> token;
	}
	return 0;
}