h,w = map(int,input().split())
s = [list(input()) for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            if i == 0 and j == 0:
                t = 0
                if s[i][j+1] == '#':
                    t += 1
                if s[i+1][j] == '#':
                    t += 1
                if s[i+1][j+1] == '#':
                    t += 1
                s[i][j] = str(t)
            elif i == 0 and j == w - 1:
                t = 0
                if s[i][j-1] == '#':
                    t += 1
                if s[i+1][j-1] == '#':
                    t += 1
                if s[i+1][j] == '#':
                    t += 1
                s[i][j] = str(t)
            elif i == h - 1 and j == 0:
                t = 0
                if s[i-1][j] == '#':
                    t += 1
                if s[i-1][j+1] == '#':
                    t += 1
                if s[i][j+1] == '#':
                    t += 1
                s[i][j] = str(t)
            elif i == h - 1 and j == w - 1:
                t = 0
                if s[i-1][j-1] == '#':
                    t += 1
                if s[i-1][j] == '#':
                    t += 1
                if s[i][j-1] == '#':
                    t += 1
                s[i][j] = str(t)
            elif i == 0:
                t = 0
                if s[i][j-1] == '#':
                    t += 1
                if s[i][j+1] == '#':
                    t += 1
                if s[i+1][j-1] == '#':
                    t += 1
                if s[i+1][j] == '#':
                    t += 1
                if s[i+1][j+1] == '#':
                    t += 1
                s[i][j] = str(t)
            elif j == 0:
                t = 0
                if s[i-1][j] == '#':
                    t += 1
                if s[i-1][j+1] == '#':
                    t += 1
                if s[i][j+1] == '#':
                    t += 1
                if s[i+1][j] == '#':
                    t += 1
                if s[i+1][j+1] == '#':
                    t += 1
                s[i][j] = str(t)
            elif i == h - 1:
                t = 0
                if s[i-1][j-1] == '#':
                    t += 1
                if s[i-1][j] == '#':
                    t += 1
                if s[i-1][j+1] == '#':
                    t += 1
                if s[i][j-1] == '#':
                    t += 1
                if s[i][j+1] == '#':
                    t += 1
                s[i][j] = str(t)
            elif j == w - 1:
                t = 0
                if s[i-1][j-1] == '#':
                    t += 1
                if s[i-1][j] == '#':
                    t += 1
                if s[i][j-1] == '#':
                    t += 1
                if s[i+1][j-1] == '#':
                    t += 1
                if s[i+1][j] == '#':
                    t += 1
                s[i][j] = str(t)
            else:
                t = 0
                if s[i-1][j-1] == '#':
                    t += 1
                if s[i-1][j] == '#':
                    t += 1
                if s[i-1][j+1] == '#':
                    t += 1
                if s[i][j-1] == '#':
                    t += 1
                if s[i][j+1] == '#':
                    t += 1
                if s[i+1][j-1] == '#':
                    t += 1
                if s[i+1][j] == '#':
                    t += 1
                if s[i+1][j+1] == '#':
                    t += 1
                s[i][j] = str(t)

for i in range(h):
    print(''.join(s[i]))