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

char check(&mine,int i,int j,int a,int b){
  int count=0;
  if(i>0){
    if(mine.at(i-1).at(j)=='#')
      count++;
    if(mine.at(i-1).at(j-1)=='#'&&j>0)
      count++;
    if(mine.at(i-1).at(j+1)=='#'&&j<b)
      count++;
  }
  if(i<a){
    if(mine.at(i+1).at(j)=='#')
      count++;
    if(j>0&&mine.at(i-1).at(j-1)=='#')
      count++;
    if(j<b&&mine.at(i-1).at(j+1)=='#')
      count++;
  }
  if(j>0&&mine.at(i).at(j-1)=='#')
    count++;
  if(j<b&&mine.at(i).at(j+1)=='#')
    count++;
  char sum=(char)count;
  return sum;
}

int main(){
  int a,b;
  cin>>a>>b;
  vector<vector<char>> mine(a,vector<char>(b));
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      cin>>mine.at(i).at(j);
    }
  }
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      if(mine.at(i).at(j)=='.')
        mine.at(i).at(j)=check(mine,i,j,a,b);
    }
  }
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      cout<<mine.at(i).at(j);
    }
    cout<<endl;
  }
}