h, w = [int(word) for word in input().split()]

s = [["."]*(w+2)]

for i in range(1, h+1):
    row = [v for v in input().split()]
    row.insert(0, ".")
    row.append(".")
    s.append(row)

s.append(["."]*(w+2))

result = s

for r in range(1, h+1):
    for c in range(1, w+1):
        if s[r][c] == "#":
            result[r][c] = "#"
        else:
            count = 0
            for r2 in [-1, 0 , 1]:
                for c2 in [-1, 0, 1]:
                    if s[r+r2][c+c2] == "#":
                        count += 1
            result[r][c] = str(count)

for r in range(1, h+1):
    print("".join(s[r][1:w+1]))
