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

s = [eval(input()) for i in range(h)]

for i in range(h):

  l = ""

  for j in range(w):

    if s[i][j] == "#":

      l += "#"

    else:

      l += str(sum([t[max(0,j-1):min(w,j+2)].count("#") for t in s[max(0,i-1):min(h,i+2)]]))

  print(l)

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

S = [list(input()) for i in range(H)]

arr = [[0]*W for i in range(H)]

for i in range(H):

  for j in range(W):

    if S[i][j] == "#":

      if i-1 >= 0 and S[i-1][j] == ".":

        arr[i-1][j] += 1

      if i+1 < H and S[i+1][j] == ".":

        arr[i+1][j] += 1

      if j-1 >= 0 and S[i][j-1] == ".":

        arr[i][j-1] += 1

      if j+1 < W and S[i][j+1] == ".":

        arr[i][j+1] += 1

      if i-1 >= 0 and j-1 >= 0 and S[i-1][j-1] == ".":

        arr[i-1][j-1] += 1

      if i-1 >= 0 and j+1 < W and S[i-1][j+1] == ".":

        arr[i-1][j+1] += 1

      if i+1 < H and j-1 >= 0 and S[i+1][j-1] == ".":

        arr[i+1][j-1] += 1

      if i+1 < H and j+1 < W and S[i+1][j+1] == ".":

        arr[i+1][j+1] += 1

      arr[i][j] = "#"

for i in range(H):

  print(*arr[i], sep="")

h, w = list(map(int, input().split()))
s = [eval(input()) for i in range(h)]
for i in range(h):
    l = ""
    for j in range(w):
        if s[i][j] == "#":
            l += "#"
        else:
            l += str(
                sum(
                    [
                        t[max(0, j - 1) : min(w, j + 2)].count("#")
                        for t in s[max(0, i - 1) : min(h, i + 2)]
                    ]
                )
            )
    print(l)

H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
arr = [[0] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            if i - 1 >= 0 and S[i - 1][j] == ".":
                arr[i - 1][j] += 1
            if i + 1 < H and S[i + 1][j] == ".":
                arr[i + 1][j] += 1
            if j - 1 >= 0 and S[i][j - 1] == ".":
                arr[i][j - 1] += 1
            if j + 1 < W and S[i][j + 1] == ".":
                arr[i][j + 1] += 1
            if i - 1 >= 0 and j - 1 >= 0 and S[i - 1][j - 1] == ".":
                arr[i - 1][j - 1] += 1
            if i - 1 >= 0 and j + 1 < W and S[i - 1][j + 1] == ".":
                arr[i - 1][j + 1] += 1
            if i + 1 < H and j - 1 >= 0 and S[i + 1][j - 1] == ".":
                arr[i + 1][j - 1] += 1
            if i + 1 < H and j + 1 < W and S[i + 1][j + 1] == ".":
                arr[i + 1][j + 1] += 1
            arr[i][j] = "#"
for i in range(H):
    print(*arr[i], sep="")

-h, w = list(map(int, input().split())) -s = [eval(input()) for i in range(h)] -for i in range(h): -    l = "" -    for j in range(w): -        if s[i][j] == "#": -            l += "#" -        else: -            l += str( -                sum( -                    [ -                        t[max(0, j - 1) : min(w, j + 2)].count("#") -                        for t in s[max(0, i - 1) : min(h, i + 2)] -                    ] -                ) -            ) -    print(l) +H, W = map(int, input().split()) +S = [list(input()) for i in range(H)] +arr = [[0] * W for i in range(H)] +for i in range(H): +    for j in range(W): +        if S[i][j] == "#": +            if i - 1 >= 0 and S[i - 1][j] == ".": +                arr[i - 1][j] += 1 +            if i + 1 < H and S[i + 1][j] == ".": +                arr[i + 1][j] += 1 +            if j - 1 >= 0 and S[i][j - 1] == ".": +                arr[i][j - 1] += 1 +            if j + 1 < W and S[i][j + 1] == ".": +                arr[i][j + 1] += 1 +            if i - 1 >= 0 and j - 1 >= 0 and S[i - 1][j - 1] == ".": +                arr[i - 1][j - 1] += 1 +            if i - 1 >= 0 and j + 1 < W and S[i - 1][j + 1] == ".": +                arr[i - 1][j + 1] += 1 +            if i + 1 < H and j - 1 >= 0 and S[i + 1][j - 1] == ".": +                arr[i + 1][j - 1] += 1 +            if i + 1 < H and j + 1 < W and S[i + 1][j + 1] == ".": +                arr[i + 1][j + 1] += 1 +            arr[i][j] = "#" +for i in range(H): +    print(*arr[i], sep="")