def calc(array, i, j, H, W):

    move = [[1, -1], [1, 0], [1, 1], [0, -1], [0, 1], [-1, 0], [-1, -1], [-1, 1]]

    num_mine = 0

    for k in range(8):

        x = i+move[k][0]

        y = j+move[k][1]

        if x >= H or x < 0 or y >= W or y < 0:

            pass

        else:

            num_mine += 1 if array[x][y] == "#" else 0

    return num_mine





def main():

    num = input().split()

    num = [int(x) for x in num]

    H = num[0]

    W = num[1]



    array = []

    for i in range(H):

        array.append(list(eval(input())))



    for i in range(H):

        for j in range(W):

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

                pass

            else:

                array[i][j] = calc(array, i, j, H, W)



    for i in range(0, num[0]):

        print(("".join(map(str, array[i]))))





if __name__ == '__main__':

    main()

num = [int(x) for x in input().split()]

array = []

for i in range(num[0]):

    array.append(list(eval(input())))





for j in range(num[0]):

    for k in range(num[1]):

        cnt = 0

        if array[j][k] != "#":

            try:

                if array[j-1][k] == "#" and j-1 != -1:

                    cnt += 1

            except IndexError:

                pass

            try:

                if array[j-1][k-1] == "#" and j-1 != -1 and k-1 != -1:

                    cnt += 1

            except IndexError:

                pass

            try:

                if array[j-1][k+1] == "#" and j-1 != -1:

                    cnt += 1

            except IndexError:

                pass

            try:

                if array[j][k-1] == "#" and k-1 != -1:

                    cnt += 1

            except IndexError:

                pass

            try:

                if array[j][k+1] == "#":

                    cnt += 1

            except IndexError:

                pass

            try:

                if array[j+1][k] == "#":

                    cnt += 1

            except IndexError:

                pass

            try:

                if array[j+1][k-1] == "#" and k-1 != -1:

                    cnt += 1

            except IndexError:

                pass

            try:

                if array[j+1][k+1] == "#":

                    cnt += 1

            except IndexError:

                pass

            array[j][k] = str(cnt)



for i in array:

    print(("".join(i)))

def calc(array, i, j, H, W):
    move = [[1, -1], [1, 0], [1, 1], [0, -1], [0, 1], [-1, 0], [-1, -1], [-1, 1]]
    num_mine = 0
    for k in range(8):
        x = i + move[k][0]
        y = j + move[k][1]
        if x >= H or x < 0 or y >= W or y < 0:
            pass
        else:
            num_mine += 1 if array[x][y] == "#" else 0
    return num_mine


def main():
    num = input().split()
    num = [int(x) for x in num]
    H = num[0]
    W = num[1]
    array = []
    for i in range(H):
        array.append(list(eval(input())))
    for i in range(H):
        for j in range(W):
            if array[i][j] == "#":
                pass
            else:
                array[i][j] = calc(array, i, j, H, W)
    for i in range(0, num[0]):
        print(("".join(map(str, array[i]))))


if __name__ == "__main__":
    main()

num = [int(x) for x in input().split()]
array = []
for i in range(num[0]):
    array.append(list(eval(input())))
for j in range(num[0]):
    for k in range(num[1]):
        cnt = 0
        if array[j][k] != "#":
            try:
                if array[j - 1][k] == "#" and j - 1 != -1:
                    cnt += 1
            except IndexError:
                pass
            try:
                if array[j - 1][k - 1] == "#" and j - 1 != -1 and k - 1 != -1:
                    cnt += 1
            except IndexError:
                pass
            try:
                if array[j - 1][k + 1] == "#" and j - 1 != -1:
                    cnt += 1
            except IndexError:
                pass
            try:
                if array[j][k - 1] == "#" and k - 1 != -1:
                    cnt += 1
            except IndexError:
                pass
            try:
                if array[j][k + 1] == "#":
                    cnt += 1
            except IndexError:
                pass
            try:
                if array[j + 1][k] == "#":
                    cnt += 1
            except IndexError:
                pass
            try:
                if array[j + 1][k - 1] == "#" and k - 1 != -1:
                    cnt += 1
            except IndexError:
                pass
            try:
                if array[j + 1][k + 1] == "#":
                    cnt += 1
            except IndexError:
                pass
            array[j][k] = str(cnt)
for i in array:
    print(("".join(i)))

-def calc(array, i, j, H, W): -    move = [[1, -1], [1, 0], [1, 1], [0, -1], [0, 1], [-1, 0], [-1, -1], [-1, 1]] -    num_mine = 0 -    for k in range(8): -        x = i + move[k][0] -        y = j + move[k][1] -        if x >= H or x < 0 or y >= W or y < 0: -            pass -        else: -            num_mine += 1 if array[x][y] == "#" else 0 -    return num_mine - - -def main(): -    num = input().split() -    num = [int(x) for x in num] -    H = num[0] -    W = num[1] -    array = [] -    for i in range(H): -        array.append(list(eval(input()))) -    for i in range(H): -        for j in range(W): -            if array[i][j] == "#": +num = [int(x) for x in input().split()] +array = [] +for i in range(num[0]): +    array.append(list(eval(input()))) +for j in range(num[0]): +    for k in range(num[1]): +        cnt = 0 +        if array[j][k] != "#": +            try: +                if array[j - 1][k] == "#" and j - 1 != -1: +                    cnt += 1 +            except IndexError: -            else: -                array[i][j] = calc(array, i, j, H, W) -    for i in range(0, num[0]): -        print(("".join(map(str, array[i])))) - - -if __name__ == "__main__": -    main() +            try: +                if array[j - 1][k - 1] == "#" and j - 1 != -1 and k - 1 != -1: +                    cnt += 1 +            except IndexError: +                pass +            try: +                if array[j - 1][k + 1] == "#" and j - 1 != -1: +                    cnt += 1 +            except IndexError: +                pass +            try: +                if array[j][k - 1] == "#" and k - 1 != -1: +                    cnt += 1 +            except IndexError: +                pass +            try: +                if array[j][k + 1] == "#": +                    cnt += 1 +            except IndexError: +                pass +            try: +                if array[j + 1][k] == "#": +                    cnt += 1 +            except IndexError: +                pass +            try: +                if array[j + 1][k - 1] == "#" and k - 1 != -1: +                    cnt += 1 +            except IndexError: +                pass +            try: +                if array[j + 1][k + 1] == "#": +                    cnt += 1 +            except IndexError: +                pass +            array[j][k] = str(cnt) +for i in array: +    print(("".join(i)))