def check(b, i, j, x, y):

 if i < 0 or j < 0 or i == x or j == y:

  return 0

 if b[i][j] == "#":

  return 1

 return 0



bounds = input().split(" ")

x = int(bounds[0])

y = int(bounds[1])

board = [None] * x

for i in range(0, x):

 k = input()

 board[i] = [None] * y

 for j in range(0, y):

  board[i][j] = k[j]



for i in range(0, x):

 for j in range(0, y):

  if board[i][j] == ".":

   p = 0

   p += check(board, i-1, j-1, x, y)

   p += check(board, i-1, j  , x, y)

   p += check(board, i-1, j+1, x, y)

   p += check(board, i  , j-1, x, y)

   p += check(board, i  , j+1, x, y)

   p += check(board, i+1, j-1, x, y)

   p += check(board, i+1, j  , x, y)

   p += check(board, i+1, j+1, x, y)

   board[i][j] = p

 z = ""

 for j in range(0, y):

  z += str(board[i][j])

 print(z)

h,w=list(map(int,input().split()))

temp=[]

e='eee'

for i in range(w-1):

	e='e'+e

temp.append(e)	

for i in range(h):

	ip=input()

	ip='e'+ip+'e'

	temp.append(ip)

temp.append(e)

n=0

op=[]	

fop=[]

for i in range(h):

	for j in range(w):

		if temp[i+1][j+1]=='.':

			if temp[i+2][j+1]=='#':

				n=n+1

			if temp[i][j+1]=='#':

				n=n+1

			if temp[i+1][j+2]=='#':

				n=n+1

			if temp[i+1][j]=='#':

				n=n+1

			if temp[i+2][j+2]=='#':

				n=n+1	

			if temp[i][j+2]=='#':

				n=n+1

			if temp[i+2][j]=='#':

				n=n+1	

			if temp[i][j]=='#':

				n=n+1

			op.append(str(n))	

			n=0

		elif temp[i+1][j+1]=='#':

			op.append('#')

	fop.append(op)

	op=[]



for i in range(h):

	print(''.join(fop[i]))
def check(b, i, j, x, y):
    if i < 0 or j < 0 or i == x or j == y:
        return 0
    if b[i][j] == "#":
        return 1
    return 0


bounds = input().split(" ")
x = int(bounds[0])
y = int(bounds[1])
board = [None] * x
for i in range(0, x):
    k = input()
    board[i] = [None] * y
    for j in range(0, y):
        board[i][j] = k[j]
for i in range(0, x):
    for j in range(0, y):
        if board[i][j] == ".":
            p = 0
            p += check(board, i - 1, j - 1, x, y)
            p += check(board, i - 1, j, x, y)
            p += check(board, i - 1, j + 1, x, y)
            p += check(board, i, j - 1, x, y)
            p += check(board, i, j + 1, x, y)
            p += check(board, i + 1, j - 1, x, y)
            p += check(board, i + 1, j, x, y)
            p += check(board, i + 1, j + 1, x, y)
            board[i][j] = p
    z = ""
    for j in range(0, y):
        z += str(board[i][j])
    print(z)

h, w = list(map(int, input().split()))
temp = []
e = "eee"
for i in range(w - 1):
    e = "e" + e
temp.append(e)
for i in range(h):
    ip = input()
    ip = "e" + ip + "e"
    temp.append(ip)
temp.append(e)
n = 0
op = []
fop = []
for i in range(h):
    for j in range(w):
        if temp[i + 1][j + 1] == ".":
            if temp[i + 2][j + 1] == "#":
                n = n + 1
            if temp[i][j + 1] == "#":
                n = n + 1
            if temp[i + 1][j + 2] == "#":
                n = n + 1
            if temp[i + 1][j] == "#":
                n = n + 1
            if temp[i + 2][j + 2] == "#":
                n = n + 1
            if temp[i][j + 2] == "#":
                n = n + 1
            if temp[i + 2][j] == "#":
                n = n + 1
            if temp[i][j] == "#":
                n = n + 1
            op.append(str(n))
            n = 0
        elif temp[i + 1][j + 1] == "#":
            op.append("#")
    fop.append(op)
    op = []
for i in range(h):
    print("".join(fop[i]))

-def check(b, i, j, x, y): -    if i < 0 or j < 0 or i == x or j == y: -        return 0 -    if b[i][j] == "#": -        return 1 -    return 0 - - -bounds = input().split(" ") -x = int(bounds[0]) -y = int(bounds[1]) -board = [None] * x -for i in range(0, x): -    k = input() -    board[i] = [None] * y -    for j in range(0, y): -        board[i][j] = k[j] -for i in range(0, x): -    for j in range(0, y): -        if board[i][j] == ".": -            p = 0 -            p += check(board, i - 1, j - 1, x, y) -            p += check(board, i - 1, j, x, y) -            p += check(board, i - 1, j + 1, x, y) -            p += check(board, i, j - 1, x, y) -            p += check(board, i, j + 1, x, y) -            p += check(board, i + 1, j - 1, x, y) -            p += check(board, i + 1, j, x, y) -            p += check(board, i + 1, j + 1, x, y) -            board[i][j] = p -    z = "" -    for j in range(0, y): -        z += str(board[i][j]) -    print(z) +h, w = list(map(int, input().split())) +temp = [] +e = "eee" +for i in range(w - 1): +    e = "e" + e +temp.append(e) +for i in range(h): +    ip = input() +    ip = "e" + ip + "e" +    temp.append(ip) +temp.append(e) +n = 0 +op = [] +fop = [] +for i in range(h): +    for j in range(w): +        if temp[i + 1][j + 1] == ".": +            if temp[i + 2][j + 1] == "#": +                n = n + 1 +            if temp[i][j + 1] == "#": +                n = n + 1 +            if temp[i + 1][j + 2] == "#": +                n = n + 1 +            if temp[i + 1][j] == "#": +                n = n + 1 +            if temp[i + 2][j + 2] == "#": +                n = n + 1 +            if temp[i][j + 2] == "#": +                n = n + 1 +            if temp[i + 2][j] == "#": +                n = n + 1 +            if temp[i][j] == "#": +                n = n + 1 +            op.append(str(n)) +            n = 0 +        elif temp[i + 1][j + 1] == "#": +            op.append("#") +    fop.append(op) +    op = [] +for i in range(h): +    print("".join(fop[i]))