#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main() {
	int H, W;

	cin >> H >> W;

	char mineField[H][W] = {};
	int counter[H][W] = {};
	

	for (int i = 0 ; i < H ; i++) {
		string s;
		cin >> s;
		for (int j = 0 ; j < W ; j++) {
			minField[i][j] = s.at(j);
		}
	}

	for (int s = 0 ; s < H ; s++) {
		for (int t = 0 ; t < W ; t++) {
			if (mineField[s][t] == '#') {

				if ( (s + 1 < H - 1) && (t + 1 < W - 1) ){
					if( mineField[s + 1][t + 1] == '.' ){
						counter[s + 1][t + 1]++;
					}
				}

				if ( s + 1 < H - 1 ){
					if( mineField[s + 1][t] == '.' ){
						counter[s + 1][t]++;
					}
				}

				if ((s + 1 < H - 1) && (t > 1) ){
					if( mineField[s + 1][t - 1] == '.' ){
						counter[s + 1][t - 1]++;
					}
				}

				if (t + 1 < W - 1) {
					if( mineField[s][t + 1] == '.' ){
						counter[s][t + 1]++;
					}
				}

				if (t > 1){
					if( mineField[s][t - 1] == '.' ){
						counter[s][t - 1]++;
					}
				}

				if ( (s > 1) && (t + 1 < W - 1) ){
					if( mineField[s - 1][t + 1] == '.' ){
						counter[s + 1][t + 1]++;
					}
				}

				if (s > 1) {
					if( mineField[s - 1][t] == '.' ){
						counter[s + 1][t]++;
					}
				}

				if (( s > 1 ) && (t > 1) ) {
					if( mineField[s - 1][t - 1] == '.' ){
						counter[s + 1][t - 1]++;
					}
				}
			}
		}
	}

	for (int s = 0 ; s < H ; s++) {
		for (int t = 0 ; t < W ; t++) {
			if (mineField[s][t] == '#') {
				cout << "#";
			} else {
				cout << counter[s][t];
			}
			cout << endl;
		}
	}
}