#include<stdio.h>
int main(){
  int i,j,h,w,a[52][52];
  char x[52][52];
  scanf("%d %d",&h,&w);
  for(i=1;i<=h;i++){
      scanf("%c",x[i]);
    }
  }
  for(i=0;i<=h+1;i++){
    for(j=0;i<=w+1;i++){
      a[i][j]=0;
    }
  }
  for(i=1;i<=h;i++){
    for(j=1;i<=w;i++){
      if(x[i][j]=='#'){
        a[i-1][j-1]++;
        a[i-1][j]++;
        a[i-1][j+1]++;
        a[i][j-1]++;
        a[i][j+1]++;
        a[i+1][j-1]++;
        a[i+1][j]++;
        a[i+1][j+1]++;
      }
    }
  }
  for(i=1;i<=h;i++){
    for(j=1;i<=w;i++){
      if(x[i][j]=='#'){printf("#");}
      else{printf("%d",a[i][j]);}
    }
    printf("\n");
  }
}