def checkmine(i,j):
    count=0
    for a in range(-1,2):
        for b in range(-1,2):
            if 0<=a+i<n and 0<=b+j<m:
                if field[a+i][b+j]=="#":count+=1
    return count

n,m=map(int,input().split())
field=[]
for i in range(n):field.append(list(input()))
for i in range(n):
    for j in range(m):
        if field[i][j]==".":field[i][j]=checkmine(i,j)
for i in field:print(''.join(map(str,i)))