h,w = map(int, raw_input().split())
s = [raw_input() for _ in range(h)]
t = []
for i in range(h):
    u = ''
    for j in range(w):
        if s[i][j] == '.':
            c = 0
            for y in range(max(0, i-1), min(i+2, h)):
                for x in range(max(0, j-1), min(j+2, w)):
                    if s[y][x] == '#':
                        c += 1
            u += str(c)
        else:
            u += s[i][j]
    t.append(u)
for u in t:
    print u
