import sys

import  math

import bisect

from statistics import *

from collections import *

from operator import itemgetter

"""

from fractions import gcd

def lcm(x, y):

    return (x * y) // gcd(x, y)

"""

stdin = sys.stdin

ni = lambda: int(ns())

na = lambda: list(map(int, stdin.readline().split()))

ns = lambda: stdin.readline()



h, w = na()

li = []

for i in range(h):

    li.append(input())

for i in range(h):

    for j in range(w):

        ct = 0

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

            print("#", end="")

        else:

            ppp = []

            for k in range(-1, 2):

                for l in range(-1, 2):

                    if 0 <= i + k <= h-1 and 0 <= j + l <= w-1:

                        ppp.append(li[i+k][j+l])

            for p in ppp:

                if p == "#":

                    ct += 1

            print(ct, end="")

    print()

import sys

import  math

import bisect

from statistics import *

from collections import *

from operator import itemgetter

"""

from fractions import gcd

def lcm(x, y):

    return (x * y) // gcd(x, y)

"""

stdin = sys.stdin

ni = lambda: int(ns())

na = lambda: list(map(int, stdin.readline().split()))

ns = lambda: stdin.readline()



h, w = na()

li = []

for i in range(h):

    li.append(input())

for i in range(h):

    for j in range(w):

        ct = 0

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

            print("#", end="")

        else:

            for p in [li[i-1+k][j-1+l] for k in range(3) for l in range(3) if 0<=i-1+k<=h-1 and 0<=j-1+l<=w-1]:

                if p == "#":

                    ct += 1

            print(ct, end="")

    print()

import sys
import math
import bisect
from statistics import *
from collections import *
from operator import itemgetter

"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
h, w = na()
li = []
for i in range(h):
    li.append(input())
for i in range(h):
    for j in range(w):
        ct = 0
        if li[i][j] == "#":
            print("#", end="")
        else:
            ppp = []
            for k in range(-1, 2):
                for l in range(-1, 2):
                    if 0 <= i + k <= h - 1 and 0 <= j + l <= w - 1:
                        ppp.append(li[i + k][j + l])
            for p in ppp:
                if p == "#":
                    ct += 1
            print(ct, end="")
    print()

import sys
import math
import bisect
from statistics import *
from collections import *
from operator import itemgetter

"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
h, w = na()
li = []
for i in range(h):
    li.append(input())
for i in range(h):
    for j in range(w):
        ct = 0
        if li[i][j] == "#":
            print("#", end="")
        else:
            for p in [
                li[i - 1 + k][j - 1 + l]
                for k in range(3)
                for l in range(3)
                if 0 <= i - 1 + k <= h - 1 and 0 <= j - 1 + l <= w - 1
            ]:
                if p == "#":
                    ct += 1
            print(ct, end="")
    print()

-            ppp = [] -            for k in range(-1, 2): -                for l in range(-1, 2): -                    if 0 <= i + k <= h - 1 and 0 <= j + l <= w - 1: -                        ppp.append(li[i + k][j + l]) -            for p in ppp: +            for p in [ +                li[i - 1 + k][j - 1 + l] +                for k in range(3) +                for l in range(3) +                if 0 <= i - 1 + k <= h - 1 and 0 <= j - 1 + l <= w - 1 +            ]: