h,w = (int(i) for i in input().split())
d = {}
nei = [-101,-100,-99,-1,1,99,100,101]
for i in range(h):
  s = input()
  for j in range(w):
    d[(i+1)*100+j+1] = s[j]
for k in d:
  if d[k] == '.':
    cnt = 0
    for l in nei:
      if k+l in d:
        if d[k+l] == '#':
          cnt += 1
    d[k] = cnt
for i in range(h):
  ans = ''
  for j in range(w):
    ans += str(d[(i+1)*100+j+1])
  print(ans)