h,w=map(int,input().split())
s=[]
s.append(input())
c = [[0] * w for i in range(h)]
for i in range(h-1):
    s.append(input())
    for j in range(w):
        p=[]
        if i ==0 and j==0:
            p=s[i][j:j+2]+s[i+1][j:j+2]
        elif i==0 and j>0:
            p=s[i][j-1:j+2]+s[i+1][j-1:j+2]
        elif i>0 and j==0:
            p = s[i-1][j:j+2]+s[i][j:j+2]+s[i+1][j:j+2]
        else:
            p = s[i-1][j-1:j+2]+s[i][j-1:j+2]+s[i+1][j-1:j+2]
        if s[i][j] == '#':
            c[i][j] = '#'
        else:
            c[i][j] = p.count('#')

for j in range(w):
    p=[]
    i=h-1
    if j==0:
        p = s[i-1][j:j+2]+s[i][j:j+2]
    else:
        p = s[i-1][j-1:j+2]+s[i][j-1:j+2]
    if s[i][j] == '#':
        c[i][j] = '#'
    else:
        c[i][j] = p.count('#')
        
for i in range(h):
  for j in range(w):
    print(c[i][j],end="")
  print('',sep='\n')