H,W=map(int,input().split(' '))
S=[['x']*(W+2)]
for i in range(H):
  S.append(['x']+list(input())+['x'])
S.append(['x']*(W+2))

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == '.':
      S[h][w] = str([S[x][y] for x in [h-1,h,h+1] for y in [w-1,w,w+1]].count('#'))
      
for i in range(H):
  print(''.join(S[i+1]).replace('x',''))