#include <bits/stdc++.h>

using namespace std;
const int N = 51;
vector<vector<int>> res(N, vector<int>(N, 0));

int dx[8] = {1,1,1,0,0,-1,-1,-1};
int dy[8] = {1,0,-1,1,-1,1,0,-1};

int main(){
    ios_base::sync_with_stdio (false);
    //freopen ("joke.in","r",stdin);
	//freopen ("joke.out","w",stdout);
	int H, W;
  	vector<string> g;
  	string s;
  	for(int i=0; i<H; ++i){
    	cin >> s;
      	g.push_back(s);
    }
  	
  	for(int y = 0; y < H; ++y){
    	for(int x = 0; x < W; ++x){
        	for(int d = 0; d < 8; ++d){
            	int xx = x + dx[d];
              	int yy = y + dy[d];
              	if(xx<W && xx>=0 && yy<H && yy>=0){
                	if(g[yy][xx]=='#'){
                    	res[y][x]++;
                    }
                }
            }
        }
    }
  	
    for(int y = 0; y < H; ++y){
    	for(int x = 0; x < W; ++x){
        	cout << ((g[yy][xx]=='#') ? '#' : res[y][x];
        }
      	cout << endl;
    }
  
    return 0;
}
