h, w = map(int, input().split())
s = [ [0] + [0 if a=='.' else 1 for a in input()] + [0] for _ in range(h)]
s = [[0 for _ in range(w+2)]] + s + [[0 for _ in range(w+2)]]

for j in range(1,h+1):
  ans = []
  for i in range(1,w+1):
    if s[j][i] == 0:
      ans.append(str(sum(s[j-1][i-1:i+2])+sum(s[j][i-1:i+2])+sum(s[j+1][i-1:i+2])))
    else:
      ans.append('#')
  print(''.join(ans))