h,w = map(int,input().split())
mine = []
for i in range(h):
    mine.append([])
    inp = input()
    for j in range(w):
        mine[i].append(inp[j])
for i in range(h):
    for j in range(w):
        if mine[i][j] == '.':
            cnt = 0
            for k in range(3):
                for l in range(3):
                    try:
                        if mine[i-1+k][j+l-1] == '#':
                            cnt+= 1
                    except:
                        continue
            mine[i][j] = str(cnt)
    print(''.join(mine[i]))