h,w = map(int,input().split())
S = []
for i in range(h):
    S.append(list(input()))
if h == 1 and w == 1:
    if S[0][0] == '.':
        print('0')
    else:
        print(S[0][0])
if h == 1 and w == 2:
    if S == [['.','#']]:
        print('1#')
    if S == [['#','#']]:
        print('##')
    if S == [['#','.']]:
        print('#1')
    if S == [['.','.']]:
        print('00')
if h == 1 and w >= 3:
    for g in range(w):
        if S[0][0] == '.':
            if S[0][1] == '#':
                S[0][0] = '1'
            else:
                S[0][0] = '0'
        if 1 <= g <= w-2:
            if S[0][g] == '.':
                S[0][g] = str(S[0][g-1:g+2].count('#'))
        if S[0][w-1] == '.':
            if S[0][w-2] == '#':
                S[0][w-1] = '1'
            else:
                S[0][w-1] = '0'
    print(''.join(S[0]))
if h >= 3 and w == 1:
    for y in range(h):
        if S[0][0] == '.':
            if S[1][0] == '#':
                S[0][0] = '1'
            else:
                S[0][0] = '0' 
        if 1 <= y <= h-2:
            if S[y][0] == '.':
                count = 0
                if S[y-1][0] == '#':
                    count += 1
                if S[y+1][0] == '#':
                    count += 1
                S[y][0] = int(count)
        if S[h-1][0] == '.':
            if S[h-2][0] == '#':
                S[h-1][0] = '1'
            else:
                S[h-1][0] = '0'
    for p in S:
        print(p[0])
if h == 2 and w == 1:
    if S == [['.'],['.']]:
        print('0')
        print('0')
    if S == [['#'],['.']]:
        print('#')
        print('1')
    if S == [['.'],['#']]:
        print('1')
        print('#')
    if S == [['#'],['#']]:
        print('#')
        print('#')
if h >= 2 and w >= 2:
    for k in range(h):
        for j in range(w):
            if S[k][j] == '.':
                if k == 0 and j == 0:
                    count = 0
                    if S[0][1] == '#':
                        count += 1 
                    count += S[1][0:2].count('#')
                    S[k][j] = str(count)
                elif k == 0 and 1 <= j <= w-2:
                    count = 0
                    count += S[0][j-1:j+2].count('#')
                    count += S[1][j-1:j+2].count('#')
                    S[k][j] = str(count)
                elif k == 0 and j == w-1:
                    count = 0
                    if S[0][j-1] == '#':
                        count += 1
                    count += S[1][j-1:].count('#')
                    S[k][j] = str(count)
                elif 1 <= k <= h-2 and j == 0:
                    count = 0
                    count += S[k-1][0:2].count('#')
                    if S[k][1] == '#':
                        count += 1 
                    count += S[k+1][0:2].count('#')
                    S[k][j] = str(count)
                elif 1 <= k <= h-2 and 1 <= j <= w-2:
                    count = 0
                    count += S[k-1][j-1:j+2].count('#')
                    count += S[k][j-1:j+2].count('#')
                    count += S[k+1][j-1:j+2].count('#')
                    S[k][j] = str(count)
                elif 1 <= k <= h-2 and j == w-1:
                    count = 0
                    count += S[k-1][j-1:].count('#')
                    count += S[k][j-1:].count('#')
                    count += S[k+1][j-1:].count('#')
                    S[k][j] = str(count)
                elif k == h-1 and j == 0:
                    count = 0
                    count += S[k-1][0:2].count('#')
                    count += S[k][1].count('#')
                    S[k][j] = str(count)
                elif k == h-1 and 1 <= j <= w-2:
                    count = 0
                    count += S[k-1][j-1:j+2].count('#')
                    count += S[k][j-1:j+2].count('#')
                    S[k][j] = str(count)
                elif k == h-1 and j == w-1:
                    count = 0
                    count += S[k-1][j-1:].count('#')
                    count += S[k][j-1:].count('#')
                    S[k][j] = str(count)
    for p in S:
        print(''.join(p))

Measured memory_bytes: 3448