h, w = gets.chomp.split(' ').map(&:to_i)
A = []
h.times do
 A << gets.chomp.split('').push('x').unshift('x')
end

h.times do |i|
  w.times do |j|
    if A[i][j+1] == "."
      B = [A[i-1][j], A[i][j], A[i+1][j], A[i-1][j+1], A[i+1][j+1], A[i-1][j+2], A[i][j+2],A[i+1][j+2]]
      n = B.find_all{|item| item =="#"}.count
      A[i][j+1] = n
    end
  end
end

h.times do |i|
  A[i].pop
  A[i].shift
  puts A[i].join('')
end
