h, w = map(int, input().split())
s = [input() for i in range(h)]
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
for i in range(h):
    for j in range(w):
        mine = 0
        for k in range(8):
            if 0 <= i+dy[k] < h and 0 <= j+dx[k] < w and s[i+dy[k]][j+dx[k]] == '#':
                mine += 1
        if s[i][j] == '.':
            s[i] = s[i].replace(".", str(mine), 1)
    print(s[i])