INTEGER(16) H,W,V
CHARACTER(51),ALLOCATABLE,DIMENSION(:)::X
READ*,H,W
ALLOCATE(X(H))
READ*,X
V=0
DO I=1,H
  DO J=1,W
    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
      X(I)(J:J)=CHAR(V+ICHAR('0'))
    ENDIF
  END DO
END DO
DO I=1,H
PRINT"(A)",TRIM(X(I))
ENDDO
END