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

l=[]

for i in range(h):

  s = list(eval(input()))

  l.append(s)

for i in range(h):

  for j in range(w):

    kazu = 0

    if l[i][j] == '.':

      if j != 0 and l[i][j-1] == '#':

        kazu += 1

      if j != w-1 and l[i][j+1] == '#':

        kazu += 1

      if i != 0 and l[i-1][j]== '#':

        kazu += 1

      if i != h-1 and l[i+1][j] == '#':

        kazu += 1

      if i >= 1 and j >= 1 and l[i-1][j-1] == '#':

        kazu += 1

      if i >= 1 and j <= w-2 and l[i-1][j+1] == '#':

        kazu += 1

      if i <= h-2 and j >= 1 and l[i+1][j-1] == '#':

        kazu += 1

      if i <= h-2 and j <= w-2 and l[i+1][j+1] == '#':

        kazu += 1

      l[i][j] = str(kazu)

for i in range(h):

  print((''.join(l[i])))
h,w = list(map(int,input().split()))

l = [['*']*(w+2)]

for i in range(h):

    l.append(['*']+list(eval(input()))+['*'])

l.append(['*']*(w+2))





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

    s = ''

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

        directions = [(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1)]

        alist = [(i+dir[0],j+dir[1]) for dir in directions]

        cnt = 0

        for a in alist:

            if l[a[0]][a[1]] == '#':

                cnt += 1

        if l[i][j] == '#':

            s += '#'

        else:

            s += str(cnt)

    print(s)
h, w = list(map(int, input().split()))
l = []
for i in range(h):
    s = list(eval(input()))
    l.append(s)
for i in range(h):
    for j in range(w):
        kazu = 0
        if l[i][j] == ".":
            if j != 0 and l[i][j - 1] == "#":
                kazu += 1
            if j != w - 1 and l[i][j + 1] == "#":
                kazu += 1
            if i != 0 and l[i - 1][j] == "#":
                kazu += 1
            if i != h - 1 and l[i + 1][j] == "#":
                kazu += 1
            if i >= 1 and j >= 1 and l[i - 1][j - 1] == "#":
                kazu += 1
            if i >= 1 and j <= w - 2 and l[i - 1][j + 1] == "#":
                kazu += 1
            if i <= h - 2 and j >= 1 and l[i + 1][j - 1] == "#":
                kazu += 1
            if i <= h - 2 and j <= w - 2 and l[i + 1][j + 1] == "#":
                kazu += 1
            l[i][j] = str(kazu)
for i in range(h):
    print(("".join(l[i])))

h, w = list(map(int, input().split()))
l = [["*"] * (w + 2)]
for i in range(h):
    l.append(["*"] + list(eval(input())) + ["*"])
l.append(["*"] * (w + 2))
for i in range(1, h + 1):
    s = ""
    for j in range(1, w + 1):
        directions = [
            (0, 1),
            (1, 1),
            (1, 0),
            (1, -1),
            (0, -1),
            (-1, -1),
            (-1, 0),
            (-1, 1),
        ]
        alist = [(i + dir[0], j + dir[1]) for dir in directions]
        cnt = 0
        for a in alist:
            if l[a[0]][a[1]] == "#":
                cnt += 1
        if l[i][j] == "#":
            s += "#"
        else:
            s += str(cnt)
    print(s)

-l = [] +l = [["*"] * (w + 2)] -    s = list(eval(input())) -    l.append(s) -for i in range(h): -    for j in range(w): -        kazu = 0 -        if l[i][j] == ".": -            if j != 0 and l[i][j - 1] == "#": -                kazu += 1 -            if j != w - 1 and l[i][j + 1] == "#": -                kazu += 1 -            if i != 0 and l[i - 1][j] == "#": -                kazu += 1 -            if i != h - 1 and l[i + 1][j] == "#": -                kazu += 1 -            if i >= 1 and j >= 1 and l[i - 1][j - 1] == "#": -                kazu += 1 -            if i >= 1 and j <= w - 2 and l[i - 1][j + 1] == "#": -                kazu += 1 -            if i <= h - 2 and j >= 1 and l[i + 1][j - 1] == "#": -                kazu += 1 -            if i <= h - 2 and j <= w - 2 and l[i + 1][j + 1] == "#": -                kazu += 1 -            l[i][j] = str(kazu) -for i in range(h): -    print(("".join(l[i]))) +    l.append(["*"] + list(eval(input())) + ["*"]) +l.append(["*"] * (w + 2)) +for i in range(1, h + 1): +    s = "" +    for j in range(1, w + 1): +        directions = [ +            (0, 1), +            (1, 1), +            (1, 0), +            (1, -1), +            (0, -1), +            (-1, -1), +            (-1, 0), +            (-1, 1), +        ] +        alist = [(i + dir[0], j + dir[1]) for dir in directions] +        cnt = 0 +        for a in alist: +            if l[a[0]][a[1]] == "#": +                cnt += 1 +        if l[i][j] == "#": +            s += "#" +        else: +            s += str(cnt) +    print(s)