h, w = map(int, input().split())

S = []
for h in range(h):
  S.append(input())

for i in range(h):
  ss = ''
  for j in range(w):
    if S[i][j] == '#':
      ss += '#'
    else:
      counter = 0
      for k in [-1, 0, 1]:
        for l in [-1, 0, 1]:
          if (k, l) == (0, 0):
            continue
          elif i+k < 0 or i+k > h-1 or j+l < 0 or j+l > w-1:
            continue
          else:
            if S[i+k][j+l] == '#':
              counter += 1
      ss += str(counter)
    print(ss)