a = [int(i) for i in input().split()]
h = a[0]
w = a[1]

table = [i for i in range(h)]
for i in range(w):
    table[i] = input()

for i in range(h):
    for j in range(w):
        if table[i][j] == '.':
            c=0
            if table[i - 1][j - 1] == '#' and 0 <= i - 1 < h and 0 <= j - 1 < w:
                c += 1
            if table[i - 1][j] == '#' and 0 <= i - 1 < h and 0 <= j< w:
                c += 1
            if table[i - 1][j+1] == '#' and 0 <= i - 1 < h and 0 <= j+1< w:
                c += 1
            if table[i][j - 1] == '#' and 0 <= i< h and 0 <= j - 1 < w:
                c += 1
            if table[i][j] == '#' and 0 <= i < h and 0 <= j< w:
                c += 1
            if table[i][j+1] == '#' and 0 <= i< h and 0 <= j+1< w:
                c += 1
            if table[i + 1][j - 1] == '#' and 0 <= i + 1 < h and 0 <= j - 1 < w:
                c += 1
            if table[i + 1][j] == '#' and 0 <= i + 1 < h and 0 <= j< w:
                c += 1
            if table[i + 1][j+1] == '#' and 0 <= i + 1 < h and 0 <= j+1< w:
                c += 1
        table[i][j] = str(c)

print(table)