num = [int(x) for x in input().split()]
array = []
for i in range(num[0]):
    array.append(list(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] == "#":
                    cnt += 1
            except IndexError:
                pass
            try:
                if array[j-1][k-1] == "#":
                    cnt += 1
            except IndexError:
                pass
            try:
                if array[j-1][k+1] == "#":
                    cnt += 1
            except IndexError:
                pass
            try:
                if array[j][k-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] == "#":
                    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))