# -*- coding:utf-8 -*-
H,W=map(int,input().split())
boxes=list()
boxes[0]=[0]*W
boxes[H+1]=[0]*W
for i in range(H):
  boxes[i+1]=list()
  boxes[i+1][0]=0
  bowes[i+1][W+1]=0
  x=input()
  for j in range(W):
    if x[j]=='.':
      boxes[i+1][j+1]=0
    elif x[j]=='#':
      boxes[i+1][j+1]=1
answer=list()
for n in range(H):
  answer[n]=list()
  for k in range(W):
    count=0
    if boxes[n][k]==1:
      count+=1
    if boxes[n][k+1]==1:
      count+=1
    if boxes[n][k+2]==1:
      count+=1
    if boxes[n+1][k]==1:
      count+=1
    if boxes[n+1][k+2]==1:
      count+=1
    if boxes[n+2][k]==1:
      count+=1
    if boxes[n+2][k+1]==1:
      count+=1
    if boxes[n+2][k+2]==1:
      count+=1
    if count==0:
      answer[n][k]='#'
	else:
      answer[n][k]=str(count)
 for v in range(H):
  answe=''.join(answer[v])
  print(answe)