#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for (auto&& si : s) cin >> si;
	for (int r = 0; r < h; r++)
	{
		for (int c = 0; c < w; c++)
			if (s[r][c] == '.')
			{
				s[r][c] = '0';
				for (int i = -1; i <= 1; i++)
					for (int j = -1; j <= 1; j++)
					{
						if (r+i >= 0 && r+i < h && c+j >= 0 && c+j < w && s[r+i][c+j] == '#') s[r][c]++;
					}
			}
		cout << s[r] << endl;
	}
	return 0;
}
