y,x = map(int, raw_input().split(" "))
mines = []
answer = []
for t in range(y):
    mines.append(list(raw_input()))

for i in range(y):
    notes = ""
    for h in range(x):
        if mines[i][h] == '.':
            count = 0
            if i != 0:
                if h != 0:
                    if mines[i-1][h-1] == "#":
                        count += 1
                if mines[i-1][h] == "#":
                    count += 1
                if h != x-1:
                    if mines[i-1][h+1] == "#":
                        count += 1
            if h != 0:
                if mines[i][h-1] == "#":
                    count += 1
            if mines[i][h] == "#":
                count += 1
            if h != x-1:
                if mines[i][h+1] == "#":
                    count += 1
            if i != y-1:
                if h != 0:
                    if mines[i+1][h-1] == "#":
                        count += 1
                if mines[i+1][h] == "#":
                    count += 1
                if h != x-1:
                    if mines[i+1][h+1] == "#":
                        count += 1
            mines[i][h] = str(count)
    notes = "".join(mines[i])
    print notes
