#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
  cin>>a>>b;
  vector<string> mine(a);
  vector<int> mine2(a*b,0);
  vector<string> mine3(a*b);
  for(int i=0;i<a;i++){
    cin>>mine;
    for(int j=0;j<b;j++){
    char d=mine[j];
    mine3[b*i+j]=d;
    if(d=='#'){
      if(j>=1){
        mine2[b*i+j-1]++;
        if(i>=1)mine2[b*(i-1)+j-1]++;
        if(i<a-1)mine2[b*(i+1)+j-1]++;
      }
      if(j<b-1){
        mine2[b*i+j+1]++;
        if(i>=1)mine2[b*(i-1)+j+1]++;
        if(i<a-1)mine2[b*(i+1)+j+1]++;
      }
      if(i>=1)mine2[b*(i-1)+j]++;
      if(i<a-1)mine2[b*(i+1)+j]++;
    }
    }
  }
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
    char d=mine3[b*i+j];
    int e=mine2[b*i+j];
    if(d=='#')cout<<'#';
    else cout<<e;
  }
  cout<<endl;
}