n,m=map(int,input().split()) maps=[[3for i inrange(m+2)]] res=[[0for i inrange(m)] for j inrange(n)] for i inrange(n): a=[3]+list(map(int, input().split()))+[3] maps.append(a) maps.append([3for i inrange(m+2)]) for i inrange(1,n+1): for j inrange(1,m+1): if maps[i][j]==1: res[i-1][j-1]=9 else: temp=0 if maps[i-1][j-1]==1: temp+=1 if maps[i-1][j]==1: temp+=1 if maps[i-1][j+1]==1: temp+=1 if maps[i][j-1]==1: temp+=1 if maps[i][j+1]==1: temp+=1 if maps[i+1][j-1]==1: temp+=1 if maps[i+1][j]==1: temp+=1 if maps[i+1][j+1]==1: temp+=1 res[i-1][j-1]=temp for i in res: print(" ".join(map(str,i)))