package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)

type Directions int
const (
	up = iota
	upRight
	right
	downRight
	down
	downLeft
	left
	upLeft
)

type Area rune
const (
	Bomb = '#'
	Space = '.'
)

func main() {
	var H,W int

	input := bufio.NewScanner(os.Stdin)
	
	input.Scan()
	H,_ = strconv.Atoi(input.Text())
	area := make([]string,H)
	
	W,_ = strconv.Atoi(input.Text())
	
	for i := 0;i < W;i++ {
		input.Scan()
		area[i] = input.Text()
	}
	
	for y,str := range area {
		charArray := []rune(area[y])
		for x,ch := range str {
			if Bomb == ch {
				continue
			}
			charArray[x] = rune(countBomb(area,W,H,x,y))
		}
		area[y] = string(charArray)
	}
	for _,val := range area {
		fmt.Printf("%s\n",val)
	}
}

func countBomb(area []string,xMax int,yMax int,x int,y int) int {
	var count int
	for dir := up;dir < upLeft;dir++ {
		if look(Directions(dir),area,x,y) {
			count++
		}
	}
	return count
}

func look(direction Directions,area []string,x int,y int) bool{
	switch direction {
	case up:
		if 0 == y || Space == area[y-1][x]{
			return false
		}
	case upRight:
		if len(area[y]) == x || 0 == y || Space ==  area[y - 1][x + 1] {
			return false
		}
	case right:
		if len(area[y]) == y || Space == area[y][x + 1] {
			return false
		}
	case downRight:
		if len(area[y]) == y || len(area) == y || Space == area[y + 1][x + 1] {
			return false
		}
	case down:
		if len(area) == y || Space == area[y + 1][x]{
			return false
		}
	case downLeft:
		if len(area) == y || 0 == x || Space == area[y + 1][x - 1] {
			return false
		}
	case left:
		if 0 == x || Space == area[y][x - 1] {
			return false
		}
	case upLeft:
		if 0 == x || 0 == y || Space == area[y - 1][x - 1] {
			return false
		}
	}
	return true
}

