H,W=map(int,input().split());S=[input()for _ in[0]*H];print('\n'.join(''.join([str(sum(s[max(0,w-1):min(W,w+2)].count('#')for s in S[max(0,h-1):min(H,h+2)])),'#'][S[h][w]=='#']for w in range(W))for h in range(H)))