import itertools

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

S = [input() for h in range(H)]

a = [[0 if cell=="." else "#" for cell in row] for row in S]



for h in range(H):

  for w in range(W):

    if S[h][w]!="#":

      continue

    for dx,dy in itertools.product([-1,0,1],repeat=2):

      x = h+dx

      y = w+dy

      if x<0 or H<=x:

        continue

      if y<0 or W<=y:

        continue

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

        continue

      a[x][y]+=1



for row in a:

  print(*row,sep="")

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

S = [(2+W)*"."]+["."+eval(input())+"." for h in range(H)]+[(2+W)*"."]



for h in range(1,1+H):

  for w in range(1,1+W):

    if S[h][w]!="#":

      s = S[h-1][w-1:w+2]+S[h][w-1]+S[h][w+1]+S[h+1][w-1:w+2]

      S[h]=S[h][:w]+str(s.count("#"))+S[h][w+1:]



for h in range(1,1+H):

  print((S[h][1:1+W]))
import itertools

H, W = map(int, input().split())
S = [input() for h in range(H)]
a = [[0 if cell == "." else "#" for cell in row] for row in S]
for h in range(H):
    for w in range(W):
        if S[h][w] != "#":
            continue
        for dx, dy in itertools.product([-1, 0, 1], repeat=2):
            x = h + dx
            y = w + dy
            if x < 0 or H <= x:
                continue
            if y < 0 or W <= y:
                continue
            if S[x][y] == "#":
                continue
            a[x][y] += 1
for row in a:
    print(*row, sep="")

H, W = list(map(int, input().split()))
S = [(2 + W) * "."] + ["." + eval(input()) + "." for h in range(H)] + [(2 + W) * "."]
for h in range(1, 1 + H):
    for w in range(1, 1 + W):
        if S[h][w] != "#":
            s = (
                S[h - 1][w - 1 : w + 2]
                + S[h][w - 1]
                + S[h][w + 1]
                + S[h + 1][w - 1 : w + 2]
            )
            S[h] = S[h][:w] + str(s.count("#")) + S[h][w + 1 :]
for h in range(1, 1 + H):
    print((S[h][1 : 1 + W]))

-import itertools - -H, W = map(int, input().split()) -S = [input() for h in range(H)] -a = [[0 if cell == "." else "#" for cell in row] for row in S] -for h in range(H): -    for w in range(W): +H, W = list(map(int, input().split())) +S = [(2 + W) * "."] + ["." + eval(input()) + "." for h in range(H)] + [(2 + W) * "."] +for h in range(1, 1 + H): +    for w in range(1, 1 + W): -            continue -        for dx, dy in itertools.product([-1, 0, 1], repeat=2): -            x = h + dx -            y = w + dy -            if x < 0 or H <= x: -                continue -            if y < 0 or W <= y: -                continue -            if S[x][y] == "#": -                continue -            a[x][y] += 1 -for row in a: -    print(*row, sep="") +            s = ( +                S[h - 1][w - 1 : w + 2] +                + S[h][w - 1] +                + S[h][w + 1] +                + S[h + 1][w - 1 : w + 2] +            ) +            S[h] = S[h][:w] + str(s.count("#")) + S[h][w + 1 :] +for h in range(1, 1 + H): +    print((S[h][1 : 1 + W]))