h,w = gets.split.map(&:to_i)
arr = []
h.times do
  arr << gets.chomp.split("")
end

class NilClass
  def method_missing(name, *args, &block)
    nil
  end
end


(0..h-1).each do |i|
  a_ar = []
  (0..w-1).each do |j|
    cnt = 0
      cnt+=1 if arr[i-1][j-1] === '#'
      cnt+=1 if arr[i-1][j] === '#'
      cnt+=1 if arr[i-1][j+1] === '#'
      cnt+=1 if arr[i][j-1] === '#'
      cnt+=1 if arr[i][j+1] === '#'
      cnt+=1 if arr[i+1][j-1] === '#'
      cnt+=1 if arr[i+1][j] === '#'
      cnt+=1 if arr[i+1][j+1] === '#'
      if arr[i][j] == '#'
        a_ar << '#'
      else
        a_ar << cnt
      end
  end
  puts a_ar.join
end
