h, w = map(int,input().split())
s = []
for i in range(h):
    s.append(list(input()))
ans = [[] for _ in range(h)]
for i in range(h):
    if i == 0:
        for j in range(w):
            if j == 0:
                if s[i][j] == ".":
                    count = 0
                    if s[i][j+1] == "#":
                        count += 1
                    if s[i+1][j+1] == "#":
                        count += 1
                    if s[i+1][j] == "#":
                        count += 1
                    ans[i].append(count)
                else:
                    ans[i].append("#")
            elif j == w-1:
                if s[i][j] == ".":
                    count = 0
                    if s[i][j-1] == "#":
                        count += 1
                    if s[i+1][j-1] == "#":
                        count += 1
                    if s[i+1][j] == "#":
                        count += 1
                    ans[i].append(count)
                else:
                    ans[i].append("#")
            else:
                if s[i][j] == ".":
                    count = 0
                    if s[i][j-1] == "#":
                        count += 1
                    if s[i][j+1] == "#":
                        count += 1
                    if s[i+1][j-1] == "#":
                        count += 1
                    if s[i+1][j] == "#":
                        count += 1
                    if s[i+1][j+1] == "#":
                        count += 1
                    ans[i].append(count)
                else:
                    ans[i].append("#")
    elif i == h-1:
        for j in range(w):
            if j == 0:
                if s[i][j] == ".":
                    count = 0
                    if s[i][j+1] == "#":
                        count += 1
                    if s[i-1][j+1] == "#":
                        count += 1
                    if s[i-1][j] == "#":
                        count += 1
                    ans[i].append(count)
                else:
                    ans[i].append("#")
            elif j == w-1:
                if s[i][j] == ".":
                    count = 0
                    if s[i][j-1] == "#":
                        count += 1
                    if s[i-1][j-1] == "#":
                        count += 1
                    if s[i-1][j] == "#":
                        count += 1
                    ans[i].append(count)
                else:
                    ans[i].append("#")
            else:
                if s[i][j] == ".":
                    count = 0
                    if s[i][j-1] == "#":
                        count += 1
                    if s[i][j+1] == "#":
                        count += 1
                    if s[i-1][j-1] == "#":
                        count += 1
                    if s[i-1][j] == "#":
                        count += 1
                    if s[i-1][j+1] == "#":
                        count += 1
                    ans[i].append(count)
                else:
                    ans[i].append("#")
    else:
        for j in range(w):
            if j == 0:
                if s[i][j] == ".":
                    count = 0
                    if s[i][j+1] == "#":
                        count += 1
                    if s[i+1][j+1] == "#":
                        count += 1
                    if s[i+1][j] == "#":
                        count += 1
                    if s[i-1][j+1] == "#":
                        count += 1
                    if s[i-1][j] == "#":
                        count += 1
                    ans[i].append(count)
                else:
                    ans[i].append("#")
            elif j == w-1:
                if s[i][j] == ".":
                    count = 0
                    if s[i][j-1] == "#":
                        count += 1
                    if s[i+1][j-1] == "#":
                        count += 1
                    if s[i+1][j] == "#":
                        count += 1
                    if s[i-1][j-1] == "#":
                        count += 1
                    if s[i-1][j] == "#":
                        count += 1
                    ans[i].append(count)
                else:
                    ans[i].append("#")
            else:
                if s[i][j] == ".":
                    count = 0
                    if s[i][j-1] == "#":
                        count += 1
                    if s[i][j+1] == "#":
                        count += 1
                    if s[i+1][j-1] == "#":
                        count += 1
                    if s[i+1][j] == "#":
                        count += 1
                    if s[i+1][j+1] == "#":
                        count += 1
                    if s[i-1][j-1] == "#":
                        count += 1
                    if s[i-1][j] == "#":
                        count += 1
                    if s[i-1][j+1] == "#":
                        count += 1
                    ans[i].append(count)
                else:
                    ans[i].append("#")

for j in range(h):
    str = ""
    for i in range(w):
        print(ans[j][i],end="")
    print()

### FIXED CODE ###

h, w = map(int, input().split())
s = [[] for _ in range(h+2)]
s[0] = ["." for _ in range(w+2)]
s[h+1] = ["." for _ in range(w+2)]
for i in range(1, h+1):
    s[i].append(".")
    line = list(input())
    for j in range(w):
        s[i].append(line[j])
    s[i].append(".")

def bomb(x,y):
    if s[y][x] == "#":
        return 1
    else:
        return 0

for y in range(1,h+1):
    for x in range(1,w+1):
        if s[y][x] == ".":
            s[y][x] = bomb(x-1,y-1) + bomb(x,y-1) + bomb(x+1,y-1) + bomb(x-1,y) + bomb(x+1,y) + bomb(x-1,y+1) + bomb(x,y+1) + bomb(x+1,y+1)

for i in range(1,h+1):
    for j in range(1,w):
        print(s[i][j], end = "")
    print(s[i][w])