h,w = map(int, input().split())
s = eval('list(input()),' *h)
for i in range(h):
    for j in range(w):
        c = 0
        for a in range(i-1,i+2):
            for b in range(j-1,j+2):
                c += all((min(a,b)>=0, a<h, b<w)) and s[a][b] == '#'
                
        if s[i][j] == '.':
            s[i][j] = c
for c in s:
    print(*c,sep='')