from sys import stdin

import math

import bisect

import heapq

import numpy as np

from math import factorial

inf = 10**10



h,w = [int(x) for x in stdin.readline().rstrip().split()]



li = [["." for i in range(w+2)]for j in range(h+2)]

for i in range(1,h+1):

    s = stdin.readline().rstrip()

    for j in range(1,w+1):

        li[i][j] = s[j-1]



lin = [[0 for i in range(w)]for j in range(h)]



for i in range(1,h+1):

    for j in range(1,j+1):

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

            lin[i-1][j-1] = "#"

        else:

            point = 0

            if li[i-1][j-1] == "#":

                point += 1

            if li[i-1][j] == "#":

                 point += 1

            if li[i-1][j+1] == "#":

                 point += 1

            if li[i][j-1] == "#":

                 point += 1

            if li[i][j+1] == "#":

                 point += 1

            if li[i+1][j-1] == "#":

                 point += 1

            if li[i+1][j] == "#":

                 point += 1

            if li[i+1][j+1] == "#":

                 point += 1

            lin[i-1][j-1] = str(point)



for i in lin:

    s = "".join(i)

    print(s)
from sys import stdin,setrecursionlimit

setrecursionlimit(10 ** 7)



h,w = list(map(int,stdin.readline().rstrip().split()))

s = [stdin.readline().rstrip() for _ in range(h)]



li = [[0 for i in range(w)]for j in range(h)]



x = [-1,0,1]

y = [-1,0,1]



for i in range(h):

    for j in range(w):

        count = 0

        for xx in x:

            for yy in y:

                if xx == 0 and yy == 0:

                    continue

                if j+xx < 0 or j+xx > w-1:

                    continue

                if i+yy < 0 or i+yy > h-1:

                    continue

                if s[i+yy][j+xx] == "#":

                    count += 1

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

            li[i][j] = "#"

        else:li[i][j] = str(count)



for i in li:

    print(("".join(i)))
from sys import stdin
import math
import bisect
import heapq
import numpy as np
from math import factorial

inf = 10**10
h, w = [int(x) for x in stdin.readline().rstrip().split()]
li = [["." for i in range(w + 2)] for j in range(h + 2)]
for i in range(1, h + 1):
    s = stdin.readline().rstrip()
    for j in range(1, w + 1):
        li[i][j] = s[j - 1]
lin = [[0 for i in range(w)] for j in range(h)]
for i in range(1, h + 1):
    for j in range(1, j + 1):
        if li[i][j] == "#":
            lin[i - 1][j - 1] = "#"
        else:
            point = 0
            if li[i - 1][j - 1] == "#":
                point += 1
            if li[i - 1][j] == "#":
                point += 1
            if li[i - 1][j + 1] == "#":
                point += 1
            if li[i][j - 1] == "#":
                point += 1
            if li[i][j + 1] == "#":
                point += 1
            if li[i + 1][j - 1] == "#":
                point += 1
            if li[i + 1][j] == "#":
                point += 1
            if li[i + 1][j + 1] == "#":
                point += 1
            lin[i - 1][j - 1] = str(point)
for i in lin:
    s = "".join(i)
    print(s)

from sys import stdin, setrecursionlimit

setrecursionlimit(10**7)
h, w = list(map(int, stdin.readline().rstrip().split()))
s = [stdin.readline().rstrip() for _ in range(h)]
li = [[0 for i in range(w)] for j in range(h)]
x = [-1, 0, 1]
y = [-1, 0, 1]
for i in range(h):
    for j in range(w):
        count = 0
        for xx in x:
            for yy in y:
                if xx == 0 and yy == 0:
                    continue
                if j + xx < 0 or j + xx > w - 1:
                    continue
                if i + yy < 0 or i + yy > h - 1:
                    continue
                if s[i + yy][j + xx] == "#":
                    count += 1
        if s[i][j] == "#":
            li[i][j] = "#"
        else:
            li[i][j] = str(count)
for i in li:
    print(("".join(i)))

-from sys import stdin -import math -import bisect -import heapq -import numpy as np -from math import factorial +from sys import stdin, setrecursionlimit -inf = 10**10 -h, w = [int(x) for x in stdin.readline().rstrip().split()] -li = [["." for i in range(w + 2)] for j in range(h + 2)] -for i in range(1, h + 1): -    s = stdin.readline().rstrip() -    for j in range(1, w + 1): -        li[i][j] = s[j - 1] -lin = [[0 for i in range(w)] for j in range(h)] -for i in range(1, h + 1): -    for j in range(1, j + 1): -        if li[i][j] == "#": -            lin[i - 1][j - 1] = "#" +setrecursionlimit(10**7) +h, w = list(map(int, stdin.readline().rstrip().split())) +s = [stdin.readline().rstrip() for _ in range(h)] +li = [[0 for i in range(w)] for j in range(h)] +x = [-1, 0, 1] +y = [-1, 0, 1] +for i in range(h): +    for j in range(w): +        count = 0 +        for xx in x: +            for yy in y: +                if xx == 0 and yy == 0: +                    continue +                if j + xx < 0 or j + xx > w - 1: +                    continue +                if i + yy < 0 or i + yy > h - 1: +                    continue +                if s[i + yy][j + xx] == "#": +                    count += 1 +        if s[i][j] == "#": +            li[i][j] = "#" -            point = 0 -            if li[i - 1][j - 1] == "#": -                point += 1 -            if li[i - 1][j] == "#": -                point += 1 -            if li[i - 1][j + 1] == "#": -                point += 1 -            if li[i][j - 1] == "#": -                point += 1 -            if li[i][j + 1] == "#": -                point += 1 -            if li[i + 1][j - 1] == "#": -                point += 1 -            if li[i + 1][j] == "#": -                point += 1 -            if li[i + 1][j + 1] == "#": -                point += 1 -            lin[i - 1][j - 1] = str(point) -for i in lin: -    s = "".join(i) -    print(s) +            li[i][j] = str(count) +for i in li: +    print(("".join(i)))