#include <iostream>
using namespace std;

char s[52][52];
	
int main() {
	int w, h;
	cin >> h >> w;
	
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			cin >> s[i][j];
		}
	}
	
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			if(s[i][j] == '#'){
				cout << '#';
				continue;
			}
			
			int c = 0;
			for(int k = -1; k <= 1; k++){
				for(int l = -1; l <= 1; l++){
					if(k == 0 && l == 0){
						continue;
					}
					
					if(s[i+k][j+l] == '#'){
						c++;
					}
				}
			}
			
			cout << c;
		}
		cout << endl;
	}
	return 0;
}