h,w = map(int,input().split())
ls = [input() for _ in range(h)]
ll = [['#']*w for _ in range(h)]
for x in range(h):
  for y in range(w):
    if ls[x][y]=='.':
      cnt = 0
      for dx,dy in ((1,0),(0,1),(-1,0),(0,-1),(1,1),(-1,1),(-1,-1),(1,-1)):
        nx,ny = x+dx,y+dy
        if not(0<=nx<h and 0<=ny<w): continue
        if ls[nx][ny]=='#': cnt += 1
      ll[x][y] = cnt
for l in ll:
  print(''.join(map(str,l)))