h,w=map(int,input().split())
s=eval('list(input()),'*h)
r=range
for i in r(h):
  for j in r(w):
    c=0
    for a in r(i-1,i+2):
      for b in r(j-1,j+2):
        c+=all((min(a,b)>=0,a<h,b<w))and s[a][b]=='#'
    if s[i][j]=='.':s[i][j]=c
for a in s:print(*a,sep='')