h,w =map(int,input().split())
s = [input() for i in range(h)]
dx = [1,1,1,0,0,-1,-1,-1]
dy = [1,-1,0,1,-1,1,-1,0]
s_out =["" for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
                s_out[i] += "#"
                continue
        for k in range(8):
            x = i + dx[k]
            y = j + dy[k]
            count = 0
            if x >= 0 and x <= h-1 and y >= 0 and y<= w-1 and s[x][y]=="#":
                count += 1
        s_out[i] += str(count)
for i in s_out:
    print(i)