INTEGER H,W,V
CHARACTER(100),ALLOCATABLE,DIMENSION(:)::X
READ*,H,W
ALLOCATE(X(H+2))
x(1)=""
X(H+2)=""
DO M=2,H+1 
  READ*,X(M)
  X(M)="."//TRIM(X(M))//"."
END DO
DO I=2,H+1
  DO J=2,W+1
    IF(X(I)(J:J)==".")THEN
      V=0
      IF(X(I-1)(J-1:J-1)=="#")V=V+1
      IF(X(I-1)( J : J )=="#")V=V+1
      IF(X(I-1)(J+1:J+1)=="#")V=V+1
      IF(X( I )(J-1:J-1)=="#")V=V+1
      IF(X( I )(J+1:J+1)=="#")V=V+1
      IF(X(I+1)(J-1:J-1)=="#")V=V+1
      IF(X(I+1)( J : J )=="#")V=V+1
      IF(X(I+1)(J+1:J+1)=="#")V=V+1
      WRITE(X(I)(J:J),"(I0)")V
      ENDIF
  END DO
END DO
DO K=2,H+1
PRINT"(A)",X(K)(2:W+1)
ENDDO
END