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

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> a(h + 2, vector<char>(w + 2,'.'));
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> a.at(i).at(j);
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j < =w; j++) {
			if (a.at(i).at(j) == '#') continue;
			int cnt = 0;
			if (a.at(i - 1).at(j - 1) == '#') cnt++;
			if (a.at(i).at(j - 1) == '#') cnt++;
			if (a.at(i + 1).at(j - 1) == '#') cnt++;
			if (a.at(i - 1).at(j) == '#') cnt++;
			if (a.at(i + 1).at(j) == '#') cnt++;
			if (a.at(i - 1).at(j+1) == '#') cnt++;
			if (a.at(i).at(j + 1) == '#') cnt++;
			if (a.at(i + 1).at(j + 1) == '#') cnt++;
			a.at(i).at(j) = (char)('0' + cnt);
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cout << a.at(i).at(j) << " ";
		}
		cout << endl;
	}
}