h,w=map(int,input().split())
s=[[0]*(w+2)]
for i in range(h):
  t=[0]
  u=input()
  for j in range(w):
    t.append(u[j])
  t.append(0)
  s.append(t)
s.append([0]*(w+2))

for i in range(1,h+1):
  v=[]
  for j in range(1,w+1):
    x=[s[i-1][j-1],s[i-1][j],s[i-1][j+1],s[i][j-1],s[i][j+1],s[i+1][j-1],s[i+1][j],s[i+1][j+1]]
    if s[i][j]=='#':
      v.append('#')
    else:
      v.append(x.count('#'))
  
  print(*v, sep='')