h,w = map(int,input().split())
s = [[j for j in input()] for i in range(h)]
for i in range(h):
  for p in range(w):
    count = 0
    if s[i][p] =='.':
      for j in range(-1,2):
        for k in range(-1,2):
          if 0 <= i+j < h and 0<= p+k < w:
            if s[i+j][p+k] == '#':
              count += 1
      s[i][p] = str(count)
for i in s:
  print("".join(i))