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

int main() {
	int H, W;
	string S[50];
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '.') {
				int count = 0;
				for (int x = i - 1; x <= i + 1; x++) {
					for (int y = j - 1; y <= j + 1; y++) {
						if (x != -1 && x != H && y != -1 && y != W && S[x][y] == '#') count++;
					}
				}
				cout << count;
			}
			else cout << "#";
		}
		cout << endl;
	}
}