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

S = []
result = []

for _ in range(H):
    S.append(list(input()))


print(S)


for i in range(H):

    result_row = ''

    for j in range(W):
        if (S[i][j] == '.'):

            try:
                a = 1 if S[i-1][j] == '#' else 0
            except IndexError:
                a = 0

            try:
                b = 1 if S[i+1][j] == '#' else 0
            except IndexError:
                b = 0

            try:
                c = 1 if S[i][j-1] == '#' else 0
            except IndexError:
                c = 0

            try:
                d = 1 if S[i][j+1] == '#' else 0
            except IndexError:
                d = 0

            try:
                e = 1 if S[i-1][j-1] == '#' else 0
            except IndexError:
                e = 0

            try:
                f = 1 if S[i-1][j+1] == '#' else 0
            except IndexError:
                f = 0

            try:
                g = 1 if S[i+1][j-1] == '#' else 0
            except IndexError:
                g = 0

            try:
                h = 1 if S[i+1][j+1] == '#' else 0
            except IndexError:
                h = 0

            result_row += str(a+b+c+d+e+f+g+h)

                
        elif (S[i][j] == '#'):
            result_row += '#'

    print(result_row)