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

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

dx = [1, 1, 0, -1, -1, -1, 0, 1]

dy = [0, 1, 1, 1, 0, -1, -1, -1]



c = 0

for i in range(H):

  if S[i] != "#" * W:

    for j in range(W):

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

        S[i][j] = "0"

      else:

        c += 1



if c != H * W:

 for x in range(H):

  for y in range(W):

    if S[x][y] == "#":

      for z in range(8):

        X = x + dx[z]

        Y = y + dy[z]

        if 0 <= X <= H-1  and  0 <= Y <= W-1:

          if S[X][Y] != "#":

            S[X][Y] = str(int(S[X][Y]) + 1)





for i in range(H):

  a = ""

  for j in range(W):

    a += S[i][j]

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

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



for s in S:

    for i in range(W):

        if s[i] == ".": s[i] = 0



for i in range(H):

    for j in range(W):

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

            if i > 0:

                if S[i-1][j] != "#": S[i-1][j] += 1

                if j > 0 and S[i-1][j-1] != "#": S[i-1][j-1] += 1

                if j < W-1 and S[i-1][j+1] != "#": S[i-1][j+1] += 1

            if i < H-1:

                if S[i+1][j] != "#": S[i+1][j] += 1

                if j > 0 and S[i+1][j-1] != "#": S[i+1][j-1] += 1

                if j < W-1 and S[i+1][j+1] != "#": S[i+1][j+1] += 1

            if j > 0 and S[i][j-1] != "#": S[i][j-1] += 1

            if j < W-1 and S[i][j+1] != "#": S[i][j+1] += 1



for s in S:

    print(("".join(map(str, s))))
H, W = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(H)]
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]
c = 0
for i in range(H):
    if S[i] != "#" * W:
        for j in range(W):
            if S[i][j] == ".":
                S[i][j] = "0"
            else:
                c += 1
if c != H * W:
    for x in range(H):
        for y in range(W):
            if S[x][y] == "#":
                for z in range(8):
                    X = x + dx[z]
                    Y = y + dy[z]
                    if 0 <= X <= H - 1 and 0 <= Y <= W - 1:
                        if S[X][Y] != "#":
                            S[X][Y] = str(int(S[X][Y]) + 1)
for i in range(H):
    a = ""
    for j in range(W):
        a += S[i][j]
    print(a)

H, W = list(map(int, input().split()))
S = [list(eval(input())) for _ in range(H)]
for s in S:
    for i in range(W):
        if s[i] == ".":
            s[i] = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            if i > 0:
                if S[i - 1][j] != "#":
                    S[i - 1][j] += 1
                if j > 0 and S[i - 1][j - 1] != "#":
                    S[i - 1][j - 1] += 1
                if j < W - 1 and S[i - 1][j + 1] != "#":
                    S[i - 1][j + 1] += 1
            if i < H - 1:
                if S[i + 1][j] != "#":
                    S[i + 1][j] += 1
                if j > 0 and S[i + 1][j - 1] != "#":
                    S[i + 1][j - 1] += 1
                if j < W - 1 and S[i + 1][j + 1] != "#":
                    S[i + 1][j + 1] += 1
            if j > 0 and S[i][j - 1] != "#":
                S[i][j - 1] += 1
            if j < W - 1 and S[i][j + 1] != "#":
                S[i][j + 1] += 1
for s in S:
    print(("".join(map(str, s))))

-dx = [1, 1, 0, -1, -1, -1, 0, 1] -dy = [0, 1, 1, 1, 0, -1, -1, -1] -c = 0 +for s in S: +    for i in range(W): +        if s[i] == ".": +            s[i] = 0 -    if S[i] != "#" * W: -        for j in range(W): -            if S[i][j] == ".": -                S[i][j] = "0" -            else: -                c += 1 -if c != H * W: -    for x in range(H): -        for y in range(W): -            if S[x][y] == "#": -                for z in range(8): -                    X = x + dx[z] -                    Y = y + dy[z] -                    if 0 <= X <= H - 1 and 0 <= Y <= W - 1: -                        if S[X][Y] != "#": -                            S[X][Y] = str(int(S[X][Y]) + 1) -for i in range(H): -    a = "" -        a += S[i][j] -    print(a) +        if S[i][j] == "#": +            if i > 0: +                if S[i - 1][j] != "#": +                    S[i - 1][j] += 1 +                if j > 0 and S[i - 1][j - 1] != "#": +                    S[i - 1][j - 1] += 1 +                if j < W - 1 and S[i - 1][j + 1] != "#": +                    S[i - 1][j + 1] += 1 +            if i < H - 1: +                if S[i + 1][j] != "#": +                    S[i + 1][j] += 1 +                if j > 0 and S[i + 1][j - 1] != "#": +                    S[i + 1][j - 1] += 1 +                if j < W - 1 and S[i + 1][j + 1] != "#": +                    S[i + 1][j + 1] += 1 +            if j > 0 and S[i][j - 1] != "#": +                S[i][j - 1] += 1 +            if j < W - 1 and S[i][j + 1] != "#": +                S[i][j + 1] += 1 +for s in S: +    print(("".join(map(str, s))))