h, w = map(int,input().split())
s = []

for i in range(h):
    i = list(input())
    s.append(i)

dx = [-1, 0, 1, -1, 1, -1, 0, 1]
dy = [1, 1, 1, 0, 0, -1, -1, -1]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue

        tmp = 0
        for t in range(8):
            ni = i + dx[t]
            nj = j + dy[t]
            if ni < 0 or h <= ni: continue
            if nj < 0 or w <= nj: continue
            if s[ni][nj] == '#':
                tmp += 1

        s[i][j] = str(tmp)

print(s)