main=do
  [h,w]<-map read.words<$>getLine
  s<-lines<$>getContents
  f h w 0 0 s
f h w i j s=
  putStr(if s!!i!!j=='#'then"#"else show(sum[if s!!tx!!ty=='#'then 1 else 0|r<-[0..7],let tx=i+(dx!!r),let ty=j+(dy!!r),tx>=0&&ty>=0&&tx<h&&ty<w]))>>
  if j+1<w then f h w i (j+1) s else
    putStrLn"">>if i+1<h then f h w (i+1) 0 s else return()
dx=[0,1,0,-1,1,1,-1,-1]
dy=[1,0,-1,0,1,-1,1,-1]