#include <stdio.h>
int main(void){
  int h,w,k[52][52]={},i,j,x,y;
  char f[50][51];
  scanf("%d%d\n",&h,&w);
  for (i=1;i<=h;i++){
    scanf("%s",f[i-1]);
    for (j=1;j<=w;j++){
      if (f[i-1][j-1]=='#'){
        for (x=-1;x<2;x++){
          for (y=-1;y<2;y++){
            k[i+x][j+y]++;
          }
        }
      }
    }
  }
  for (i=1;i<=h;i++){
    for (j=1;j<=w;j++){
      if (f[i-1][j-1]=='#') printf("#");
      else printf("%d",k[i][j]);
    }
    printf("\n");
  }
  return 0;
}