h,w = map(int,input().split())
s=[]
for _ in range(h):
    s.append(list(input()))
for i in range(h):
    for j in range(w):
        if s[i][j]!="#":
            cnt = 0
            for k in range(-1,2):
                for l in range(-1,2):
                    if 0<=i+k<h and 0<=j+l<w and s[i+k][j+l]=="#":
                        cnt += 1
            s[i][j]=str(cnt)
for ss in s:
    print("".join(ss))
