#include<bits/stdc++.h>
using namespace std;

int main(){
  int H,W;
  int bomb = 0;
  cin >> H >> W;
  vector<char> c(H*W);
  for(int i=0;i<H*W;i++)
    cin >> c.at(i);
  for(int i=0;i<H*W;i++){
    if(c.at(i)=='.'){
      if(c.at(i-W-1)=='#')
        bomb++;
      if(c.at(i-W)=='#')
        bomb++;
      if(c.at(i-W+1)=='#')
        bomb++;
      if(c.at(i-1)=='#')
        bomb++;
      if(c.at(i+1)=='#')
        bomb++;
      if(c.at(i+W-1)=='#')
        bomb++;
      if(c.at(i+W)=='#')
        bomb++;
      if(c.at(i+W+1)=='#')
        bomb++;
      c.at(i) = bomb;
      bomb = 0;
    }
  }
  for (int i=0;i<H;i++){
    for (int j=0;j<W;j++){
      cout << c.at(i+j)
    }
    cout << endl;
  }
  
}