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

l=[]

for i in range(h):

  l.append(eval(input()))

al=[]

for i in range(h):

  s=''

  for j in range(w):

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

      s+='#'

      continue

    c=0

    if i>0 and j>0 and l[i-1][j-1]=='#':

      c+=1

    if i>0 and l[i-1][j]=='#':

      c+=1

    if i>0 and j<w-1 and l[i-1][j+1]=='#':

      c+=1

    if j>0 and l[i][j-1]=='#':

      c+=1

    if j<w-1 and l[i][j+1]=='#':

      c+=1

    if i<h-1 and j>0 and l[i+1][j-1]=='#':

      c+=1

    if i<h-1 and l[i+1][j]=='#':

      c+=1

    if i<h-1 and j<w-1 and l[i+1][j+1]=='#':

      c+=1

    s+=str(c)

  al.append(s)

for i in range(h):

  print((al[i]))
# 入力

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



l=[]

for i in range(H):

  l.append(list(eval(input())))



for i in range(H):

  for j in range(W):

    # 地雷数のカウンタ

    c=0



    # '#'の場合はなにもしない

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

      pass



    # '#'以外の場合

    else:

      # 左上

      if 0<i and 0<j and l[i-1][j-1]=='#':

        c+=1

      # 上

      if 0<i and l[i-1][j]=='#':

        c+=1

      # 右上

      if 0<i and j<W-1 and l[i-1][j+1]=='#':

        c+=1

      # 左

      if 0<j and l[i][j-1]=='#':

        c+=1

      # 右

      if j<W-1 and l[i][j+1]=='#':

        c+=1

      # 左下

      if i<H-1 and 0<j and l[i+1][j-1]=='#':

        c+=1

      # 下

      if i<H-1 and l[i+1][j]=='#':

        c+=1

      # 右下

      if i<H-1 and j<W-1 and l[i+1][j+1]=='#':

        c+=1



      l[i][j]=str(c)



# 出力

for i in range(H):

  print((''.join(l[i])))
h, w = list(map(int, input().split()))
l = []
for i in range(h):
    l.append(eval(input()))
al = []
for i in range(h):
    s = ""
    for j in range(w):
        if l[i][j] == "#":
            s += "#"
            continue
        c = 0
        if i > 0 and j > 0 and l[i - 1][j - 1] == "#":
            c += 1
        if i > 0 and l[i - 1][j] == "#":
            c += 1
        if i > 0 and j < w - 1 and l[i - 1][j + 1] == "#":
            c += 1
        if j > 0 and l[i][j - 1] == "#":
            c += 1
        if j < w - 1 and l[i][j + 1] == "#":
            c += 1
        if i < h - 1 and j > 0 and l[i + 1][j - 1] == "#":
            c += 1
        if i < h - 1 and l[i + 1][j] == "#":
            c += 1
        if i < h - 1 and j < w - 1 and l[i + 1][j + 1] == "#":
            c += 1
        s += str(c)
    al.append(s)
for i in range(h):
    print((al[i]))

# 入力
H, W = list(map(int, input().split()))
l = []
for i in range(H):
    l.append(list(eval(input())))
for i in range(H):
    for j in range(W):
        # 地雷数のカウンタ
        c = 0
        # '#'の場合はなにもしない
        if l[i][j] == "#":
            pass
        # '#'以外の場合
        else:
            # 左上
            if 0 < i and 0 < j and l[i - 1][j - 1] == "#":
                c += 1
            # 上
            if 0 < i and l[i - 1][j] == "#":
                c += 1
            # 右上
            if 0 < i and j < W - 1 and l[i - 1][j + 1] == "#":
                c += 1
            # 左
            if 0 < j and l[i][j - 1] == "#":
                c += 1
            # 右
            if j < W - 1 and l[i][j + 1] == "#":
                c += 1
            # 左下
            if i < H - 1 and 0 < j and l[i + 1][j - 1] == "#":
                c += 1
            # 下
            if i < H - 1 and l[i + 1][j] == "#":
                c += 1
            # 右下
            if i < H - 1 and j < W - 1 and l[i + 1][j + 1] == "#":
                c += 1
            l[i][j] = str(c)
# 出力
for i in range(H):
    print(("".join(l[i])))

-h, w = list(map(int, input().split())) +# 入力 +H, W = list(map(int, input().split())) -for i in range(h): -    l.append(eval(input())) -al = [] -for i in range(h): -    s = "" -    for j in range(w): +for i in range(H): +    l.append(list(eval(input()))) +for i in range(H): +    for j in range(W): +        # 地雷数のカウンタ +        c = 0 +        # '#'の場合はなにもしない -            s += "#" -            continue -        c = 0 -        if i > 0 and j > 0 and l[i - 1][j - 1] == "#": -            c += 1 -        if i > 0 and l[i - 1][j] == "#": -            c += 1 -        if i > 0 and j < w - 1 and l[i - 1][j + 1] == "#": -            c += 1 -        if j > 0 and l[i][j - 1] == "#": -            c += 1 -        if j < w - 1 and l[i][j + 1] == "#": -            c += 1 -        if i < h - 1 and j > 0 and l[i + 1][j - 1] == "#": -            c += 1 -        if i < h - 1 and l[i + 1][j] == "#": -            c += 1 -        if i < h - 1 and j < w - 1 and l[i + 1][j + 1] == "#": -            c += 1 -        s += str(c) -    al.append(s) -for i in range(h): -    print((al[i])) +            pass +        # '#'以外の場合 +        else: +            # 左上 +            if 0 < i and 0 < j and l[i - 1][j - 1] == "#": +                c += 1 +            # 上 +            if 0 < i and l[i - 1][j] == "#": +                c += 1 +            # 右上 +            if 0 < i and j < W - 1 and l[i - 1][j + 1] == "#": +                c += 1 +            # 左 +            if 0 < j and l[i][j - 1] == "#": +                c += 1 +            # 右 +            if j < W - 1 and l[i][j + 1] == "#": +                c += 1 +            # 左下 +            if i < H - 1 and 0 < j and l[i + 1][j - 1] == "#": +                c += 1 +            # 下 +            if i < H - 1 and l[i + 1][j] == "#": +                c += 1 +            # 右下 +            if i < H - 1 and j < W - 1 and l[i + 1][j + 1] == "#": +                c += 1 +            l[i][j] = str(c) +# 出力 +for i in range(H): +    print(("".join(l[i])))