#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin >> h >> w;
  
  char data[h + 2][w + 2];
  
  for(int i = 0 ; i <= h + 1 ; i++){
    data[0][i] = ".";
    data[h + 1][i] = ".";
  }
  
  for(int i = 1 ; i <= h ; i++){
    data[i][0] = ".";
    data[i][w + 1] = ".";
    
    string temp;
    cin >> temp;
    
    for(int j = 1 ; j <= w ; j++){
      data[i][j] = temp.at(j - 1);
    }
  }
  
  for(int i = 1 ; i <= h ; i++){
    for(int j = 1 ; j <= w ; j++){
      if(data[i][j] == "."){
        char cnt = 0;
        if(data[i-1][j-1] == "#")cnt++;
        if(data[i-1][j] == "#")cnt++;
        if(data[i-1][j+1] == "#")cnt++;
        if(data[i][j-1] == "#")cnt++;
        if(data[i][j+1] == "#")cnt++;
        if(data[i+1][j-1] == "#")cnt++;
        if(data[i+1][j] == "#")cnt++;
        if(data[i+1][j+1] == "#")cnt++;
        cout << cnt;
      }else{
        cout << "#";
      }
    }
    cout << endl;
  }
}