#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;
	vector<string> data(H);
	for (int i = 0; i < H; i++) cin >> data[i];
	for (int i = 0; i < H; i++) for (int k = 0; k < W; k++) if (data[i][k] == '.') {
		int hoge =0;
		for (int y = i-1; y <= i+1; y++) for (int x = k-1; x <= k+1; x++) {
			if (y >= 0 && y < H && x >= 0 && x < W && data[y][x] == '#') hoge++;
		}
		data[i][k] = hoge+'0';
	}
	for (int i = 0; i < H; i++) cout << data[i] << endl;
	return 0;
}
