# ABC075 B - Minesweeper

H,W = list(map(int,input().split()))



G = [['' for _ in range(W+2)] for _ in range(H+2)]

Ans = [[0 for _ in range(W+2)] for _ in range(H+2)]



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

    S = eval(input())

    for j,s in enumerate(S):

        G[i][j+1]= s



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

    for j in range(W):

        # 1行目

        if i == 1:

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

                Ans[i][j+1] += 1

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

            #     Ans[i][j+1] = '#' 

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

                Ans[i][j+1] += 1

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

                Ans[i][j+1] += 1

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

                Ans[i][j+1] += 1

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

                Ans[i][j+1] += 1

            continue

        # 最終行

        if i == H:

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

                Ans[i][j+1] += 1

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

            #     Ans[i][j+1] = '#' 

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

                Ans[i][j+1] += 1

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

                Ans[i][j+1] += 1

            if G[i-1][j+1] == '#':

                Ans[i][j+1] += 1

            if G[i-1][j] == '#':

                Ans[i][j+1] += 1

            continue



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

            Ans[i][j+1] += 1

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

        #     Ans[i][j+1] = '#' 

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

            Ans[i][j+1] += 1

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

            Ans[i][j+1] += 1

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

            Ans[i][j+1] += 1

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

            Ans[i][j+1] += 1 

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

            Ans[i][j+1] += 1

        if G[i-1][j+1] == '#':

            Ans[i][j+1] += 1

        if G[i-1][j] == '#':

            Ans[i][j+1] += 1



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

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

        Ans[i][j] = str(Ans[i][j])

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

            Ans[i][j] = '#'



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

    s = ''

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

        s += Ans[i][j]

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

s=[eval(input()) for i in range(h)]

a=[[0]*w for i in range(h)]



if h==1 and w==1:

  if s[0]=="#":

    print("#")

  else:

    print((0))

elif h==1 and w>1:

  for i in range(w):

    t=0

    if i==0:

      if s[0][i+1]=="#":t+=1

    elif 0<i<w-1:

      if s[0][i+1]=="#":t+=1

      if s[0][i-1]=="#":t+=1

    elif i==w-1:

      if s[0][i-1]=="#":t+=1

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

      a[0][i]="#"

    else:

      a[0][i]=t

  tt=""

  for aa in a:

    for aaa in aa:

      tt+=str(aaa)

  print((str(tt)))



elif w==1 and h>1:

  for i in range(h):

    t=0

    if i==0:

      if s[i+1]=="#":t+=1

    elif 0<i<h-1:

      if s[i+1]=="#":t+=1

      if s[i-1]=="#":t+=1

    elif i==h-1:

      if s[i-1]=="#":t+=1

    if s[i]=="#":

      a[i][0]="#"

    else:

      a[i][0]=t

  for aa in a:

    print((*aa))

elif w>1 and h>1:

  for i in range(h):

    for j in range(w):

      t=0

      if i==0:

        if j==0:

          if s[i][j+1]=="#":t+=1

          if s[i+1][j+1]=="#":t+=1

          if s[i+1][j]=="#":t+=1

        elif 0<j<w-1:

          if s[i][j+1]=="#":t+=1

          if s[i+1][j+1]=="#":t+=1

          if s[i+1][j]=="#":t+=1

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

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

        elif j==w-1:

          if s[i+1][j]=="#":t+=1

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

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

      elif 0<i<h-1:

        if j==0:

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

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

          if s[i][j+1]=="#":t+=1

          if s[i+1][j+1]=="#":t+=1

          if s[i+1][j]=="#":t+=1

        elif 0<j<w-1:

          if s[i][j+1]=="#":t+=1

          if s[i+1][j+1]=="#":t+=1

          if s[i+1][j]=="#":t+=1

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

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

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

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

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

        elif j==w-1:

          if s[i+1][j]=="#":t+=1

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

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

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

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

      elif i==h-1:

        if j==0:

          if s[i][j+1]=="#":t+=1

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

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

        elif 0<j<w-1:

          if s[i][j+1]=="#":t+=1

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

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

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

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

        elif j==w-1:

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

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

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

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

        a[i][j]="#"

      else:

        a[i][j]=t

  for aa in a:

    tt=""

    for aaa in aa:

      tt+=str(aaa)

    print(tt)
# ABC075 B - Minesweeper
H, W = list(map(int, input().split()))
G = [["" for _ in range(W + 2)] for _ in range(H + 2)]
Ans = [[0 for _ in range(W + 2)] for _ in range(H + 2)]
for i in range(1, H + 1):
    S = eval(input())
    for j, s in enumerate(S):
        G[i][j + 1] = s
for i in range(1, H + 1):
    for j in range(W):
        # 1行目
        if i == 1:
            if G[i][j + 2] == "#":
                Ans[i][j + 1] += 1
            # if G[i][j+1] == '#':
            #     Ans[i][j+1] = '#'
            if G[i][j] == "#":
                Ans[i][j + 1] += 1
            if G[i + 1][j + 2] == "#":
                Ans[i][j + 1] += 1
            if G[i + 1][j + 1] == "#":
                Ans[i][j + 1] += 1
            if G[i + 1][j] == "#":
                Ans[i][j + 1] += 1
            continue
        # 最終行
        if i == H:
            if G[i][j + 2] == "#":
                Ans[i][j + 1] += 1
            # if G[i][j+1] == '#':
            #     Ans[i][j+1] = '#'
            if G[i][j] == "#":
                Ans[i][j + 1] += 1
            if G[i - 1][j + 2] == "#":
                Ans[i][j + 1] += 1
            if G[i - 1][j + 1] == "#":
                Ans[i][j + 1] += 1
            if G[i - 1][j] == "#":
                Ans[i][j + 1] += 1
            continue
        if G[i][j + 2] == "#":
            Ans[i][j + 1] += 1
        # if G[i][j+1] == '#':
        #     Ans[i][j+1] = '#'
        if G[i][j] == "#":
            Ans[i][j + 1] += 1
        if G[i + 1][j + 2] == "#":
            Ans[i][j + 1] += 1
        if G[i + 1][j + 1] == "#":
            Ans[i][j + 1] += 1
        if G[i + 1][j] == "#":
            Ans[i][j + 1] += 1
        if G[i - 1][j + 2] == "#":
            Ans[i][j + 1] += 1
        if G[i - 1][j + 1] == "#":
            Ans[i][j + 1] += 1
        if G[i - 1][j] == "#":
            Ans[i][j + 1] += 1
for i in range(1, H + 1):
    for j in range(1, W + 1):
        Ans[i][j] = str(Ans[i][j])
        if G[i][j] == "#":
            Ans[i][j] = "#"
for i in range(1, H + 1):
    s = ""
    for j in range(1, W + 1):
        s += Ans[i][j]
    print(s)

h, w = list(map(int, input().split()))
s = [eval(input()) for i in range(h)]
a = [[0] * w for i in range(h)]
if h == 1 and w == 1:
    if s[0] == "#":
        print("#")
    else:
        print((0))
elif h == 1 and w > 1:
    for i in range(w):
        t = 0
        if i == 0:
            if s[0][i + 1] == "#":
                t += 1
        elif 0 < i < w - 1:
            if s[0][i + 1] == "#":
                t += 1
            if s[0][i - 1] == "#":
                t += 1
        elif i == w - 1:
            if s[0][i - 1] == "#":
                t += 1
        if s[0][i] == "#":
            a[0][i] = "#"
        else:
            a[0][i] = t
    tt = ""
    for aa in a:
        for aaa in aa:
            tt += str(aaa)
    print((str(tt)))
elif w == 1 and h > 1:
    for i in range(h):
        t = 0
        if i == 0:
            if s[i + 1] == "#":
                t += 1
        elif 0 < i < h - 1:
            if s[i + 1] == "#":
                t += 1
            if s[i - 1] == "#":
                t += 1
        elif i == h - 1:
            if s[i - 1] == "#":
                t += 1
        if s[i] == "#":
            a[i][0] = "#"
        else:
            a[i][0] = t
    for aa in a:
        print((*aa))
elif w > 1 and h > 1:
    for i in range(h):
        for j in range(w):
            t = 0
            if i == 0:
                if j == 0:
                    if s[i][j + 1] == "#":
                        t += 1
                    if s[i + 1][j + 1] == "#":
                        t += 1
                    if s[i + 1][j] == "#":
                        t += 1
                elif 0 < j < w - 1:
                    if s[i][j + 1] == "#":
                        t += 1
                    if s[i + 1][j + 1] == "#":
                        t += 1
                    if s[i + 1][j] == "#":
                        t += 1
                    if s[i + 1][j - 1] == "#":
                        t += 1
                    if s[i][j - 1] == "#":
                        t += 1
                elif j == w - 1:
                    if s[i + 1][j] == "#":
                        t += 1
                    if s[i + 1][j - 1] == "#":
                        t += 1
                    if s[i][j - 1] == "#":
                        t += 1
            elif 0 < i < h - 1:
                if j == 0:
                    if s[i - 1][j] == "#":
                        t += 1
                    if s[i - 1][j + 1] == "#":
                        t += 1
                    if s[i][j + 1] == "#":
                        t += 1
                    if s[i + 1][j + 1] == "#":
                        t += 1
                    if s[i + 1][j] == "#":
                        t += 1
                elif 0 < j < w - 1:
                    if s[i][j + 1] == "#":
                        t += 1
                    if s[i + 1][j + 1] == "#":
                        t += 1
                    if s[i + 1][j] == "#":
                        t += 1
                    if s[i + 1][j - 1] == "#":
                        t += 1
                    if s[i][j - 1] == "#":
                        t += 1
                    if s[i - 1][j - 1] == "#":
                        t += 1
                    if s[i - 1][j] == "#":
                        t += 1
                    if s[i - 1][j + 1] == "#":
                        t += 1
                elif j == w - 1:
                    if s[i + 1][j] == "#":
                        t += 1
                    if s[i + 1][j - 1] == "#":
                        t += 1
                    if s[i][j - 1] == "#":
                        t += 1
                    if s[i - 1][j - 1] == "#":
                        t += 1
                    if s[i - 1][j] == "#":
                        t += 1
            elif i == h - 1:
                if j == 0:
                    if s[i][j + 1] == "#":
                        t += 1
                    if s[i - 1][j + 1] == "#":
                        t += 1
                    if s[i - 1][j] == "#":
                        t += 1
                elif 0 < j < w - 1:
                    if s[i][j + 1] == "#":
                        t += 1
                    if s[i - 1][j + 1] == "#":
                        t += 1
                    if s[i - 1][j] == "#":
                        t += 1
                    if s[i - 1][j - 1] == "#":
                        t += 1
                    if s[i][j - 1] == "#":
                        t += 1
                elif j == w - 1:
                    if s[i - 1][j] == "#":
                        t += 1
                    if s[i - 1][j - 1] == "#":
                        t += 1
                    if s[i][j - 1] == "#":
                        t += 1
            if s[i][j] == "#":
                a[i][j] = "#"
            else:
                a[i][j] = t
    for aa in a:
        tt = ""
        for aaa in aa:
            tt += str(aaa)
        print(tt)

-# ABC075 B - Minesweeper -H, W = list(map(int, input().split())) -G = [["" for _ in range(W + 2)] for _ in range(H + 2)] -Ans = [[0 for _ in range(W + 2)] for _ in range(H + 2)] -for i in range(1, H + 1): -    S = eval(input()) -    for j, s in enumerate(S): -        G[i][j + 1] = s -for i in range(1, H + 1): -    for j in range(W): -        # 1行目 -        if i == 1: -            if G[i][j + 2] == "#": -                Ans[i][j + 1] += 1 -            # if G[i][j+1] == '#': -            #     Ans[i][j+1] = '#' -            if G[i][j] == "#": -                Ans[i][j + 1] += 1 -            if G[i + 1][j + 2] == "#": -                Ans[i][j + 1] += 1 -            if G[i + 1][j + 1] == "#": -                Ans[i][j + 1] += 1 -            if G[i + 1][j] == "#": -                Ans[i][j + 1] += 1 -            continue -        # 最終行 -        if i == H: -            if G[i][j + 2] == "#": -                Ans[i][j + 1] += 1 -            # if G[i][j+1] == '#': -            #     Ans[i][j+1] = '#' -            if G[i][j] == "#": -                Ans[i][j + 1] += 1 -            if G[i - 1][j + 2] == "#": -                Ans[i][j + 1] += 1 -            if G[i - 1][j + 1] == "#": -                Ans[i][j + 1] += 1 -            if G[i - 1][j] == "#": -                Ans[i][j + 1] += 1 -            continue -        if G[i][j + 2] == "#": -            Ans[i][j + 1] += 1 -        # if G[i][j+1] == '#': -        #     Ans[i][j+1] = '#' -        if G[i][j] == "#": -            Ans[i][j + 1] += 1 -        if G[i + 1][j + 2] == "#": -            Ans[i][j + 1] += 1 -        if G[i + 1][j + 1] == "#": -            Ans[i][j + 1] += 1 -        if G[i + 1][j] == "#": -            Ans[i][j + 1] += 1 -        if G[i - 1][j + 2] == "#": -            Ans[i][j + 1] += 1 -        if G[i - 1][j + 1] == "#": -            Ans[i][j + 1] += 1 -        if G[i - 1][j] == "#": -            Ans[i][j + 1] += 1 -for i in range(1, H + 1): -    for j in range(1, W + 1): -        Ans[i][j] = str(Ans[i][j]) -        if G[i][j] == "#": -            Ans[i][j] = "#" -for i in range(1, H + 1): -    s = "" -    for j in range(1, W + 1): -        s += Ans[i][j] -    print(s) +h, w = list(map(int, input().split())) +s = [eval(input()) for i in range(h)] +a = [[0] * w for i in range(h)] +if h == 1 and w == 1: +    if s[0] == "#": +        print("#") +    else: +        print((0)) +elif h == 1 and w > 1: +    for i in range(w): +        t = 0 +        if i == 0: +            if s[0][i + 1] == "#": +                t += 1 +        elif 0 < i < w - 1: +            if s[0][i + 1] == "#": +                t += 1 +            if s[0][i - 1] == "#": +                t += 1 +        elif i == w - 1: +            if s[0][i - 1] == "#": +                t += 1 +        if s[0][i] == "#": +            a[0][i] = "#" +        else: +            a[0][i] = t +    tt = "" +    for aa in a: +        for aaa in aa: +            tt += str(aaa) +    print((str(tt))) +elif w == 1 and h > 1: +    for i in range(h): +        t = 0 +        if i == 0: +            if s[i + 1] == "#": +                t += 1 +        elif 0 < i < h - 1: +            if s[i + 1] == "#": +                t += 1 +            if s[i - 1] == "#": +                t += 1 +        elif i == h - 1: +            if s[i - 1] == "#": +                t += 1 +        if s[i] == "#": +            a[i][0] = "#" +        else: +            a[i][0] = t +    for aa in a: +        print((*aa)) +elif w > 1 and h > 1: +    for i in range(h): +        for j in range(w): +            t = 0 +            if i == 0: +                if j == 0: +                    if s[i][j + 1] == "#": +                        t += 1 +                    if s[i + 1][j + 1] == "#": +                        t += 1 +                    if s[i + 1][j] == "#": +                        t += 1 +                elif 0 < j < w - 1: +                    if s[i][j + 1] == "#": +                        t += 1 +                    if s[i + 1][j + 1] == "#": +                        t += 1 +                    if s[i + 1][j] == "#": +                        t += 1 +                    if s[i + 1][j - 1] == "#": +                        t += 1 +                    if s[i][j - 1] == "#": +                        t += 1 +                elif j == w - 1: +                    if s[i + 1][j] == "#": +                        t += 1 +                    if s[i + 1][j - 1] == "#": +                        t += 1 +                    if s[i][j - 1] == "#": +                        t += 1 +            elif 0 < i < h - 1: +                if j == 0: +                    if s[i - 1][j] == "#": +                        t += 1 +                    if s[i - 1][j + 1] == "#": +                        t += 1 +                    if s[i][j + 1] == "#": +                        t += 1 +                    if s[i + 1][j + 1] == "#": +                        t += 1 +                    if s[i + 1][j] == "#": +                        t += 1 +                elif 0 < j < w - 1: +                    if s[i][j + 1] == "#": +                        t += 1 +                    if s[i + 1][j + 1] == "#": +                        t += 1 +                    if s[i + 1][j] == "#": +                        t += 1 +                    if s[i + 1][j - 1] == "#": +                        t += 1 +                    if s[i][j - 1] == "#": +                        t += 1 +                    if s[i - 1][j - 1] == "#": +                        t += 1 +                    if s[i - 1][j] == "#": +                        t += 1 +                    if s[i - 1][j + 1] == "#": +                        t += 1 +                elif j == w - 1: +                    if s[i + 1][j] == "#": +                        t += 1 +                    if s[i + 1][j - 1] == "#": +                        t += 1 +                    if s[i][j - 1] == "#": +                        t += 1 +                    if s[i - 1][j - 1] == "#": +                        t += 1 +                    if s[i - 1][j] == "#": +                        t += 1 +            elif i == h - 1: +                if j == 0: +                    if s[i][j + 1] == "#": +                        t += 1 +                    if s[i - 1][j + 1] == "#": +                        t += 1 +                    if s[i - 1][j] == "#": +                        t += 1 +                elif 0 < j < w - 1: +                    if s[i][j + 1] == "#": +                        t += 1 +                    if s[i - 1][j + 1] == "#": +                        t += 1 +                    if s[i - 1][j] == "#": +                        t += 1 +                    if s[i - 1][j - 1] == "#": +                        t += 1 +                    if s[i][j - 1] == "#": +                        t += 1 +                elif j == w - 1: +                    if s[i - 1][j] == "#": +                        t += 1 +                    if s[i - 1][j - 1] == "#": +                        t += 1 +                    if s[i][j - 1] == "#": +                        t += 1 +            if s[i][j] == "#": +                a[i][j] = "#" +            else: +                a[i][j] = t +    for aa in a: +        tt = "" +        for aaa in aa: +            tt += str(aaa) +        print(tt)