#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n ;
  int w;
  cin >> n >> w;
  int ans = 1;
  char list[n][w];
  for(int i = 0; i < n; i++){
    string s;
    getline(cin, s);
    for(int j = 0; j < w; j++){
      list[i][j] = s.at(j);
    }
  }
  
  for(int i = 0; i < n; i++){
    if( i == 0 ) {
      for(int j = 0; j < w; j++){    
        int num = 0;
        if(j == 0) {
			if(list[i+1][j] == "#")num++;      
			if(list[i][j+1] == "#")num++;      
			if(list[i+1][j+1] == "#")num++;      
        } else if (j < w-2) {
			if(list[i][j+1] == "#")num++;      
			if(list[i][j-1] == "#")num++;      
			if(list[i+1][j-1] == "#")num++;
          	if(list[i+1][j] == "#")num++;      
			if(list[i+1][j+1] == "#")num++;         
        } else if (j == w-1) {
			if(list[i][j-1] == "#")num++;      
			if(list[i+1][j-1] == "#")num++;      
			if(list[i+1][j] == "#")num++;            
        }
        if(list[i][j] != "#") list[i][j] = (char)num;
      }	
      
    } else if (i < n-2) {
      for(int j = 0; j < w; j++){    
        int num = 0;
        if(j == 0) {
      		if(list[i-1][j] == "#")num++;      
			if(list[i-1][j+1] == "#")num++;      
			if(list[i][j+1] == "#")num++;
          	if(list[i+1][j] == "#")num++;      
			if(list[i+1][j+1] == "#")num++;         
        } else if (j < w-2) {
			if(list[i-1][j-1] == "#")num++;      
			if(list[i-1][j] == "#")num++;   
   			if(list[i-1][j+1] == "#")num++;      
			if(list[i][j-1] == "#")num++;
          	if(list[i][j+1] == "#")num++;      
			if(list[i+1][j-1] == "#")num++;         
			if(list[i+1][j] == "#")num++;         
			if(list[i+1][j+1] == "#")num++;         
        } else if (j == w-1) {
          if(list[i-1][j-1] == "#")num++;      
			if(list[i-1][j] == "#")num++;      
			if(list[i][j-1] == "#")num++;
          	if(list[i+1][j-1] == "#")num++;      
			if(list[i+1][j] == "#")num++;         
        }
        if(list[i][j] != "#") list[i][j] = (char)num;
      }	
    
    } else if (i == n-1){
      for(int j = 0; j < w; j++){    
        int num = 0;
        if(j == 0) {
			if(list[i-1][j] == "#")num++;      
			if(list[i-1][j+1] == "#")num++;      
			if(list[i][j+1] == "#")num++;            
        } else if (j < w-2) {
			if(list[i-1][j-1] == "#")num++;      
			if(list[i-1][j] == "#")num++;      
			if(list[i-1][j+1] == "#")num++;                  
			if(list[i][j-1] == "#")num++;      
			if(list[i][j+1] == "#")num++;      
        } else if (j == w-1) {
			if(list[i-1][j-1] == "#")num++;      
			if(list[i-1][j] == "#")num++;      
			if(list[i][j-1] == "#")num++;            
      
        }
        if(list[i][j] != "#") list[i][j] = (char)num;      
      }	
    }
  }

   for(int i = 0; i < n; i++){
      for(int j = 0; j < w; j++){
      cout >> list[i][j];
      }
      cout >> endl;
   }
}
