def main():
    h, w = map(int, input().split())
    b = []
    for _ in range(h):
        b.append(input())

    # b[1][1] -> b[0][0], b[0][1], b[0][2], b[1][0], b[1][2], b[2][0], b[2][1], b[2][2]

    ans = []
    for i in range(h):
        e = []
        for j in range(w):
            e.append(0)
        ans.append(e)

    for i in range(h):
        for j in range(w):
            count = 0
            v = b[i][j]
            if v == "#":
                ans[i][j] = '#'
                continue

            for k in range(-1, 2):
                for l in range(-1, 2):
                    if i + k < 0 or i + k >= h:
                        pass
                    elif j + l < 0 or j + l >= w:
                        pass
                    else:
                        if b[i + k][j + l] == "#":
                            count += 1
            ans[i][j] = count

    print(ans)


if __name__ == '__main__':
    main()
