#https://beta.atcoder.jp/contests/abc075
# -*- coding: utf-8 -*-
h,w = map(int,input().split())
bomb = []
for _ in range(h):
    bomb.append(list(list(input())))

for y in range(h):
    for x in range(w):
        if bomb[y][x] == '.':
            counter = 0
            for yy in list([-1,0,1]):
                for xx in list([-1,0,1]):
                    try:
                        if bomb[y+yy][x+xx]=='#': counter += 1
                    except IndexError:
                        counter += 0
            bomb[y][x] = counter

for y in range(h):
    string = ''
    for x in range(w): string += str(bomb[y][x])
    print(string)
