H, W = map(int,input().split())
S = [input() for _ in range(H)]

result = [[0 for _ in range(W+1)]for _ in range(H+1)]
for i in range(H):
  for j in range(W):
    if(S[i][j] == '#'):
      result[i][j] = '#'
      if(result[i-1][j-1] != '#'):
        result[i-1][j-1] += 1
      if(result[i-1][j] != '#'):
        result[i-1][j] += 1
      if(result[i-1][j+1] != '#'):
        result[i-1][j+1] += 1
      if(result[i][j-1] != '#'):
        result[i][j-1] += 1
      if(result[i][j+1] != '#'):
        result[i][j+1] += 1
      if(result[i+1][j-1] != '#'):
        result[i+1][j-1] += 1
      if(result[i+1][j] != '#'):
        result[i+1][j] += 1
      if(result[i+1][j+1] != '#'):
        result[i+1][j+1] += 1

for r in result[:-1]:
  print(''.join(list(map(str,r[:H]))))