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

def mines(s,h,w)
  sum = 0
  (h-1..h+1).each do |h|
    next if s[h] == nil
    (w-1..w+1).each do |w|
      next if s[w] == nil
      sum += 1 if s[h][w] == "#"
    end
  end
  return sum
end

h.times do |h|
  w.times do |w|
    next if
    print s[h][w] == '#' ? "#" : mines(s,h,w)
  end
  print "\n"
end