H,W = map(int,raw_input().split(" "))
field = [raw_input() for i in range(H)]



def calc(h,w):
    res = 0
    for i in range(-1,2):
        for j in range(-1,2):
            nh = h + i
            nw = w + j
            
            if nh >= 0 and nh < H and nw >= 0 and nw < W and (not (nh == h and nw == w)):
                if field[nh][nw] == "#":
                    res+=1
    return res




for h,line in enumerate(field):
    newline = ""
    for w,c in enumerate(line):
        if c == "#":
            newline += "#"
        else:
            newline += str(calc(h,w))
    print newline

