H, W = list(map(int,input().split()))

S = [eval(input()) for _ in range(H)]



for i in range(H):

  rs = ''

  for j in range(W):

    if(S[i][j] == '#'):

      rs += '#'

    else:

      tmp = 0

      for s in S[max(0, i-1): min(H, i+2)]:

        tmp += s[max(0, j-1): min(W, j+2)].count('#')

      rs += str(tmp)

  print(rs)
H, W = list(map(int,input().split()))

S = [eval(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[:W])))))
H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
for i in range(H):
    rs = ""
    for j in range(W):
        if S[i][j] == "#":
            rs += "#"
        else:
            tmp = 0
            for s in S[max(0, i - 1) : min(H, i + 2)]:
                tmp += s[max(0, j - 1) : min(W, j + 2)].count("#")
            rs += str(tmp)
    print(rs)

H, W = list(map(int, input().split()))
S = [eval(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[:W])))))

+result = [[0 for _ in range(W + 1)] for _ in range(H + 1)] -    rs = "" -            rs += "#" -        else: -            tmp = 0 -            for s in S[max(0, i - 1) : min(H, i + 2)]: -                tmp += s[max(0, j - 1) : min(W, j + 2)].count("#") -            rs += str(tmp) -    print(rs) +            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[:W])))))