#ABC075B

h,w=map(int,raw_input().split())
l=[]
for i in xrange(h):
 l.append(list(raw_input()))
for y in xrange(h):
 for x in xrange(w):
  if l[y][x]=='#':
   continue
  cnt=0
  for dy in [-1,0,1]:
   for dx in [-1,0,1]:
    ny=y+dy
    nx=x+dx
    if 0<=ny<h and 0<=nx<w:
     if l[ny][nx]=='#':
      cnt+=1
  l[y][x]=str(cnt)
for i in xrange(h):
 print ''.join(l[i])
