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

int main(){
  int H,W;
  cin >> H >> W;
  int mat_num[H+2][W+2] = {};
  string sh,sm,sl,s0;
  for(int j=0;j<W+2;j++){
    s0+='.';
  }
  sh = s0;
  sl = s0;
  for(int i=1;i<H+1;i++){
    cin >> sm;
    sm = '.'+sm+'.';
    for(int j=1;j<W+1;j++){
      mat_num[i][j] +=
        (sh.at(j-1)=='#')+(sh.at(j)=='#')+(sh.at(j+1)=='#')+
        (sm.at(j-1)=='#')+(sm.at(j)=='#')+(sm.at(j+1)=='#')+
        (sl.at(j-1)=='#')+(sl.at(j)=='#')+(sl.at(j+1)=='#');
    }
    if(i>1){
      for(int j=1;j<W+1;j++){
        if(sh.at(j)=='#'){
          cout << '#';
        }else{
          cout << mat_num[i][j];
        }
      }
      cout << endl;
      if(i==H){
        for(int j=1;j<W+1;j++){
          if(sm.at(j)=='#'){
            cout << '#';
          }else{
            cout << mat_num[i][j];
          }	
        }
        cout << endl;
      }
    }
    sh = sm;
    //sm = sl;
    sl = s0;
  }
  return 0;
}
