h,w = map(int,input().split())
S = [input() for i in range(h)]
for i in range(h):
    for j in range(w):
        if S[i][j] == '#' :
            print('#',end='')
            continue
        cnt = 0
        for dx in [-1,0,1]:
            for dy in [-1,0,1]:
                if not 0 <= i+dx < h or not 0 <= j+dy < w: continue
                if S[i+dx][j+dy] == '#' : cnt += 1
        print(cnt,end='')
    print()