H,W=map(int,raw_input().split())
s=[raw_input() for r in xrange(H)]
# s[h][w]
dx = [1,1,0,-1,-1,-1,0,1]
dy = [0,1,1,1,0,-1,-1,-1]
for r in xrange(H):
  buf = []
  for c in xrange(W):
    if s[r][c] == '#':
      buf.append('#')
    else:
      cnt = 0
      for i in xrange(8):
        ri = r + dx[i]
        ci = c + dy[i]
        if (0 <= ri < H) and (0 <= ci < W):
          if s[ri][ci] == '#':
            cnt += 1
      buf.append(str(cnt))
  print ''.join(buf)
