h, w = gets.chomp.split.map(&:to_i)
strs = h.times.map { gets.chomp.chars }
res = Array.new(h).map{Array.new(w, 0)}

h.times do |i|
  w.times do |j|
    if strs[i][j] == '#'
      res[i][j] = '#'
    else
      count = 0
      count += 1 if i!=0 &&  j!=0      && strs[i-1][j-1] == '#'
      count += 1 if i!=0               && strs[i-1][j]   == '#'
      count += 1 if i!=0 &&  j < w-1   && strs[i-1][j+1] == '#'
      count += 1 if          j!=0      && strs[i][j-1]   == '#'
      count += 1 if          j < w-1   && strs[i][j+1]   == '#'
      count += 1 if i < h-1 && j!= 0   && strs[i+1][j-1] == '#'
      count += 1 if i < h-1            && strs[i+1][j]   == '#'
      count += 1 if i < h-1 && j < w-1 && strs[i+1][j+1] == '#'
      res[i][j] = count
    end
  end
end

puts res.each{ |line| puts line.join }