#include <iostream>
#include <vector>
#include <set>

using namespace std;
typedef vector<vector<int> > vii;

struct P {
	int r;
	int c;
	P(int rr, int cc) {
		r = rr;
		c = cc;
	}
};
struct Pcmp {
	bool operator () (const P &p1, const P &p2) const {
		return ((p1.r < p2.r) || (p1.r == p2.r && p1.c < p2.c));
	}
};

void printgrid(vii &grid) {
	for (int r = 0; r < grid.size(); r++) {
		for (int c = 0; c < grid[0].size(); c++) {
			cout << grid[r][c];
		}
		cout << endl;
	}
}
void removeBomb(vii &grid, vii &grid2, P &p) {
	int h = grid.size();
	int w = grid[0].size();
	for (int dr = -1; dr <= 1; dr++) {
		for (int dc = -1; dc <= 1; dc++) {
			if (dr == 0 && dc == 0) continue;
			int r = p.r + dr;
			int c = p.c + dc;
			if (r >= 0 && r < h && c >= 0 && c < w) {
				if (grid[r][c] >= 0) {
					grid2[r][c]--;
				}
			}
		}
	}
}

bool placeBomb(vii &grid, vii &grid2, P &p) {
	//cout << "before: " << endl;
	//printgrid(grid2);
	int h = grid.size();
	int w = grid[0].size();
	bool success = true;
	for (int dr = -1; dr <= 1; dr++) {
		for (int dc = -1; dc <= 1; dc++) {
			if (dr == 0 && dc == 0) continue;
			int r = p.r + dr;
			int c = p.c + dc;
			if (r >= 0 && r < h && c >= 0 && c < w) {
				if (grid[r][c] >= 0) {
					grid2[r][c]++;
					if (grid2[r][c] > grid[r][c]) {
						success = false;
					}
				}
			}
		}
	}
	//cout << "after: " << endl;
	//printgrid(grid2);
	if (!success) {
		removeBomb(grid, grid2, p);
	}
	return success;
}

bool place(vii &grid, vii &grid2, P &p, int d, bool check) {
	//cout << "before: " << endl;
	//printgrid(grid2);
	int h = grid.size();
	int w = grid[0].size();
	bool success = true;
	for (int dr = -1; dr <= 1; dr++) {
		for (int dc = -1; dc <= 1; dc++) {
			if (dr == 0 && dc == 0) continue;
			int r = p.r + dr;
			int c = p.c + dc;
			if (r >= 0 && r < h && c >= 0 && c < w) {
				if (grid[r][c] >= 0) {
					grid2[r][c] += d;
					if (d * grid2[r][c] > d * grid[r][c]) {
						success = false;
					}
				}
			}
		}
	}
	//cout << "after: " << endl;
	//printgrid(grid2);
	if (check && !success) {
		place(grid, grid2, p, -d, false);
	}
	return success;
}

// a very very slow dfs bruteforce - try all possible ways to place mines ><
bool dfs(vii &grid, vii &grid2, vii &grid3, vector<P> edgepts, vector<P> &pts, int i) {
	int h = grid.size();
	int w = grid[0].size();
	if (i == pts.size()) {
		for (int j = 0; j < edgepts.size(); j++) {
			P curr = edgepts[j];
			if (grid[curr.r][curr.c] != grid2[curr.r][curr.c]) {
				//cerr << "wrong combo!" << endl;
				//printgrid(grid);
				return false;
			}
		}
		//cerr << "success!" << endl;
		//printgrid(grid);
		//cerr << endl;
		//printgrid(grid2);
		return true;
	}
	P p = pts[i];

	bool bomb = false;
	bool nobomb = false;
	// try placing bomb
	if (place(grid, grid2, p, 1, true)) {
		bomb = dfs(grid, grid2, grid3, edgepts, pts, i+1);
		place(grid, grid2, p, -1, false);
	}

	// try placing empty
	if (place(grid, grid3, p, -1, true)) {
		nobomb = dfs(grid, grid2, grid3, edgepts, pts, i+1);
		place(grid, grid3, p, 1, false);
	}

	if (!bomb && !nobomb) return false;

	//cerr << endl;
	//printgrid(grid);

	// mark cell
	int curr = grid[p.r][p.c];
	if (bomb && !nobomb && (curr == -1 || curr == -2)) {
		grid[p.r][p.c] = -2;
	} else if (!bomb && nobomb && (curr == -1 || curr == -3)) {
		grid[p.r][p.c] = -3;
	} else {
		grid[p.r][p.c] = -4;
	}

	return true;
}

int main() {
	int w, h;
	cin >> w >> h;

	vii grid(h, vector<int>(w, 0));
	for (int r = 0; r < h; r++) {
		for (int c = 0; c < w; c++) {
			char s;
			cin >> s;
			if ('0' <= s && s <= '9') {
				grid[r][c] = s - '0';
			} else if (s == '.') {
				grid[r][c] = -1;
			} else {
				return 1;
			}
			//cerr << grid[r][c];
		}
		//cerr << endl;
	}

	set<P, Pcmp> sqs;
	vii grid2(h, vector<int>(w, 0));
	vii grid3(h, vector<int>(w, 8));
	vector<P> edgepts;
	for (int r = 0; r < h; r++) {
		for (int c = 0; c < w; c++) {
			if (grid[r][c] < 0) continue;
			bool yes = false;
			int count = 0;
			for (int rr = -1; rr <= 1; rr++) {
				for (int cc = -1; cc <= 1; cc++) {
					if (rr == 0 && cc == 0) continue;
					int nr = r + rr;
					int nc = c + cc;
					if (nr >= 0 && nr < h && nc >= 0 && nc < w && grid[nr][nc] == -1) {
						sqs.insert(P(nr, nc));
						yes = true;
						count++;
					}
				}
			}
			if (yes) {
				edgepts.push_back(P(r, c));
				grid3[r][c] = count;
			}
		}
	}
	vector<P> pts;
	for (set<P, Pcmp>::iterator it = sqs.begin(); it != sqs.end(); ++it) {
		pts.push_back(*it);
	}
	for (int i = 0; i < pts.size(); i++) {
		//cerr << pts[i].r << " " << pts[i].c << endl;
	}
	for (int i = 0; i < edgepts.size(); i++) {
		//cerr << edgepts[i].r << " " << edgepts[i].c << endl;
	}
	dfs(grid, grid2, grid3, edgepts, pts, 0);
	for (int r = 0; r < h; r++) {
		for (int c = 0; c < w; c++) {
			if (grid[r][c] >= 0) {
				cout << grid[r][c];
			} else if (grid[r][c] == -2) {
				cout << '*';
			} else if (grid[r][c] == -3) {
				cout << ' ';
			} else if (grid[r][c] == -4){
				cout << '.';
			} else {
				cout << '.';
			}
		}
		cout << endl;
	}
}